drawing shadow around a view slows down my transition,CALayer,ios

家住魔仙堡 提交于 2019-12-11 09:40:03

问题


MyViewControllerB.xib contains

view( UIView )
  |
  |__image (UIImageView)
  |
  |__view (UIView)
  |
  |__text (UITextView)
  |
  |__view (UIView) ( shadow is adding at here )

Then I am adding a shadow around the view at the bottom as following

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.bottomView.layer setMasksToBounds:NO];
    self.bottomView.layer.shadowColor   =   [UIColor blackColor].CGColor;
    self.bottomView.layer.shadowRadius  =   5;
    self.bottomView.layer.shadowOpacity =   1;
    self.bottomView.layer.shadowOffset  =   CGSizeMake(0  , 0 );
}

when I am doing pushViewController: animated: at MyViewControllerA :

@implementation MyViewControllerA
    MyViewControllerB  *controller     =   [[MyViewControllerB alloc] initWithNibName:@"MyViewControllerB" bundle:nil];
    [self.navigationController pushViewController:controller animated:YES];

Then the transition is not smooth at all. However, if it remove a block of codes used to draw a shadow, the transition is smooth as usual

Do you have any ideas about this issue. Please help if you experienced it before Thanks


回答1:


Specify the CALayer shadowPath. Apple says, "Specifying an explicit path usually improves rendering performance."




回答2:


If Jon's suggestion doesn't work, you might try taking UIImage snapshots of your views and use those during the animation. We did that for one project - put a UIImageView over the actual view and then removed it at the end of the animation. Shadows are slow on iOS.




回答3:


You can tell the CALayer to rasterize the shadow.



来源:https://stackoverflow.com/questions/13096983/drawing-shadow-around-a-view-slows-down-my-transition-calayer-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!