0

コントローラにカスタム ビューを配置しましたが、カスタム ビューの高さが非常に高くなっています。次に、非常に遅いコントローラーをスクロールすると

テスト環境:iOS5.0+、iPod touch

カスタムビュー:

 @interface UICommonView : UIView
    //.....
 @end

 @implementation UICommonView
 //.....
 -(void)setBorder:(CGFloat)width color:(UIColor*)color
 {
     self.frameColor = color;
     self.frameWidth = width;
     [self.layer setBorderWidth:width];  
     [self.layer setBorderColor:[color CGColor]];  
 }
 -(void)makeShadow
 {
     self.layer.shadowOpacity = 0.7f;
     self.layer.shadowOffset = CGSizeMake(5.0f,3.0f);
     self.layer.shadowColor =[[UIColor blackColor] CGColor];
 }
 -(void)makeCornerRadius:(CGFloat)_cornerRadius
{
    self.cornerRadius = _cornerRadius;
    [self.layer setMasksToBounds:NO];
    [self.layer setCornerRadius:_cornerRadius];
 }
 @end

コントローラ:

//contentView is UICommonView  
//scrollView is UIScrollView on controller

-(void)viewDidLoad
{
     [self.contentView makeShadow];
     [self.contentView makeCornerRadius:5.0f];
     [self.contentView setBorder:4.0f color:[UIColor white]];
     // self.contentView.backgroundColor = //......
     [self.contentView setFrame:CGRectMake(0,0,320,1200)];
     [self.scrollView addSubview:contentView];
     scrollerView.contentSize = CGSizeMake(320,1300);
     //add other view
     //I tested, only custom View impact speed
}

最適化する方法。ありがとう!!

4

1 に答える 1

0

通常、シャドウにたどるパスを指定すると、シャドウはより効率的になります。

-(void)makeShadow
{
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.layer.bounds cornerRadius:self.cornerRadius];
    self.layer.shadowPath = path.CGPath; 
    self.layer.shadowOpacity = 0.7f;
    self.layer.shadowOffset = CGSizeMake(5.0f,3.0f);
    self.layer.shadowColor =[[UIColor blackColor] CGColor];
}

ただし、ビューの四角形と角の半径の両方を参照しているため、[self makeShadow]両方を呼び出す必要があります。

-(void)makeCornerRadius:(CGFloat)_cornerRadius

内だけでなく

-(void)setFrame

そうすれば、フレームまたは角の半径が変更されるたびに、それに応じて影が更新されます。これにより、よりスムーズなパフォーマンスが得られるはずです。

于 2012-11-10T06:02:23.077 に答える