2012-10-09 74 views
0

我有一個自定義UIImageView這將插入這樣一個子層:調整大小的UIImageView剪輯子

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     small_ = frame; 
     float newX = self.center.x - ((self.frame.size.width*SELECTED_SCALE_VALUE)*0.5); 
     float newY = self.center.y - ((self.frame.size.height*SELECTED_SCALE_VALUE)*0.5); 
     big_ = CGRectMake(newX, newY, self.frame.size.width*SELECTED_SCALE_VALUE, self.frame.size.height*SELECTED_SCALE_VALUE); 

     [self setupSubviews]; 
    } 
    return self; 
} 

- (void)setupSubviews 
{ 
    shadowImage_ = [[UIImage imageNamed:@"gallery_shadow_frame"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 20, 20, 20)]; 
    shadowImageView_ = [[UIImageView alloc] initWithFrame:[self shadowFrame]]; 
    shadowImageView_.image = shadowImage_; 
    shadowImageView_.backgroundColor = [UIColor blueColor]; 
    [self.layer insertSublayer:[shadowImageView_ layer] atIndex:0]; 
} 

當我後來調整UIImageView它剪輯的子層的框架:

- (void)makeBig 
{ 
    self.frame = big_; 
    // shadowImageView_.frame = [self shadowFrame]; 
} 

- (void)makeSmall 
{ 
    self.frame = small_; 
    // shadowImageView_.frame = [self shadowFrame]; 
} 

授予完整的畫面,也有這樣的:

- (CGRect)shadowFrame 
{ 
    int x = -X_BORDER; 
    int y = -Y_BORDER; 
    int width = self.frame.size.width + X_BORDER * 2; 
    int height = self.frame.size.height + Y_BORDER * 2; 
    return CGRectMake(x, y, width, height); 
} 

我如何調整UIImageView,但阻止它從剪輯是shadowImageView_ sublayer

回答

1

你試過

self.layer.masksToBounds = NO;