2013-10-22 1 views
0

아직 iOS 7로 업데이트되지 않은 iOS 6 앱이 있습니다. iOS 7에만 나타나는 내 그림자와 관련된 이상한 색상 문제가 있습니다. 때로는 정상적으로 보일 때가 있고 때로는 색이 보일 수도 있습니다.iOS 7에서 내 iOS 6 앱을 실행할 때 내보기에서 그림자가 제대로 나타나지 않는 이유는 무엇입니까?

정상은 (시간의 50 %는 그림자가 아이폰 OS 7에 일반적으로 표시) :.. 시간의

enter image description here

컬러 (50 %가이 방법을 나타은 위에 같은 검은 있어야한다 보인다)과 뷰에서 움직이는 일이 :

enter image description here enter image description here

누구나 어떤 아이디어가? 여기에 2 년 넘게 사용해온 코드가 있습니다. 이 작업을 수행하는 더 좋은 방법이 있습니까? 업데이트 된 API 호출이 올바르지 않습니까?

ShadowedTableView.h

#import <UIKit/UIKit.h> 
#import <QuartzCore/QuartzCore.h> 

@interface ShadowedTableView : UITableView 
{ 
    CAGradientLayer *originShadow; 
    CAGradientLayer *topShadow; 
    CAGradientLayer *bottomShadow; 
} 

@end 

CAGradientLayer가의 RGBA를 필요로 보인다

#import "ShadowedTableView.h" 

#define SHADOW_HEIGHT 20.0 
#define SHADOW_INVERSE_HEIGHT 10.0 
#define SHADOW_RATIO (SHADOW_INVERSE_HEIGHT/SHADOW_HEIGHT) 

@implementation ShadowedTableView 

// 
// shadowAsInverse: 
// 
// Create a shadow layer 
// 
// Parameters: 
// inverse - if YES then shadow fades upwards, otherwise shadow fades downwards 
// 
// returns the constructed shadow layer 
// 
- (CAGradientLayer *)shadowAsInverse:(BOOL)inverse 
{ 
    CAGradientLayer *newShadow = [[CAGradientLayer alloc] init]; 
    CGRect newShadowFrame = 
     CGRectMake(0, 0, self.frame.size.width, 
      inverse ? SHADOW_INVERSE_HEIGHT : SHADOW_HEIGHT); 
    newShadow.frame = newShadowFrame; 
    newShadow.colors = 
     @[(__bridge id)(inverse ? 
         ([self.backgroundColor colorWithAlphaComponent:0.0].CGColor) : 
         ([UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:inverse ? (SHADOW_INVERSE_HEIGHT/SHADOW_HEIGHT) * 0.5 : 0.5].CGColor)), 
     (__bridge id)(inverse ? 
         ([UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:inverse ? (SHADOW_INVERSE_HEIGHT/SHADOW_HEIGHT) * 0.5 : 0.5].CGColor) : 
         ([self.backgroundColor colorWithAlphaComponent:0.0].CGColor))]; 
    return newShadow; 
} 

// 
// layoutSubviews 
// 
// Override to layout the shadows when cells are laid out. 
// 
- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 

    // 
    // Construct the origin shadow if needed 
    // 
    if (!originShadow) 
    { 
     originShadow = [self shadowAsInverse:NO]; 
     [self.layer insertSublayer:originShadow atIndex:0]; 
    } 
    else if (![(self.layer.sublayers)[0] isEqual:originShadow]) 
    { 
     [self.layer insertSublayer:originShadow atIndex:0]; 
    } 

    [CATransaction begin]; 
    [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; 

    // 
    // Stretch and place the origin shadow 
    // 
    CGRect originShadowFrame = originShadow.frame; 
    originShadowFrame.size.width = self.frame.size.width; 
    originShadowFrame.origin.y = self.contentOffset.y; 
    originShadow.frame = originShadowFrame; 

    [CATransaction commit]; 

    if (self.style == UITableViewStylePlain) 
    { 
     NSArray *indexPathsForVisibleRows = [self indexPathsForVisibleRows]; 
     if ([indexPathsForVisibleRows count] == 0) 
     { 
      [topShadow removeFromSuperlayer]; 
      topShadow = nil; 
      [bottomShadow removeFromSuperlayer]; 
      bottomShadow = nil; 
      return; 
     } 

     NSIndexPath *firstRow = indexPathsForVisibleRows[0]; 
     if ([firstRow section] == 0 && [firstRow row] == 0) 
     { 
      UIView *cell = [self cellForRowAtIndexPath:firstRow]; 
      if (!topShadow) 
      { 
       topShadow = [self shadowAsInverse:YES]; 
       [cell.layer insertSublayer:topShadow atIndex:0]; 
      } 
      else if ([cell.layer.sublayers indexOfObjectIdenticalTo:topShadow] != 0) 
      { 
       [cell.layer insertSublayer:topShadow atIndex:0]; 
      } 

      CGRect shadowFrame = topShadow.frame; 
      shadowFrame.size.width = cell.frame.size.width; 
      shadowFrame.origin.y = -SHADOW_INVERSE_HEIGHT; 
      topShadow.frame = shadowFrame; 
     } 
     else 
     { 
      [topShadow removeFromSuperlayer]; 
      topShadow = nil; 
     } 

     NSIndexPath *lastRow = [indexPathsForVisibleRows lastObject]; 
     if ([lastRow section] == [self numberOfSections] - 1 && 
      [lastRow row] == [self numberOfRowsInSection:[lastRow section]] - 1) 
     { 
      UIView *cell = 
      [self cellForRowAtIndexPath:lastRow]; 
      if (!bottomShadow) 
      { 
       bottomShadow = [self shadowAsInverse:NO]; 
       [cell.layer insertSublayer:bottomShadow atIndex:0]; 
      } 
      else if ([cell.layer.sublayers indexOfObjectIdenticalTo:bottomShadow] != 0) 
      { 
       [cell.layer insertSublayer:bottomShadow atIndex:0]; 
      } 

      CGRect shadowFrame = bottomShadow.frame; 
      shadowFrame.size.width = cell.frame.size.width; 
      shadowFrame.origin.y = cell.frame.size.height; 
      bottomShadow.frame = shadowFrame; 
     } 
     else 
     { 
      [bottomShadow removeFromSuperlayer]; 
      bottomShadow = nil; 
     } 
    } 
} 

// 
// dealloc 
// 
// Releases instance memory. 
// 


@end 
+0

이 세부 사항을 기억하지 수 있지만 그림자가 탐색 막대에 업데이 트를 표시 않았다 방법 . –

답변

1

ShadowedTableView.m {0,0,0,0}의 조화를 의미 완전히 투명 색상을 만들려면 모드가 iOS 7에서 변경되었습니다.이 경우 레이더를 적용했습니다 (# 15336983).

([self.backgroundColor colorWithAlphaComponent:0.0].CGColor) :

으로 : 어떤 경우

는 해결 방법은 교체하는 것입니다

([UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0].CGColor) :

관련 문제