【问题标题】:iPad app - CALayer makes it very laggy when rotatingiPad 应用程序 - CALayer 使其在旋转时非常滞后
【发布时间】:2012-09-07 07:08:15
【问题描述】:

我目前正在开发一个通用应用程序,在我的一个视图控制器中,我有以下 xib:

View
 -ImageView
 -TableView
 -ImageView
 -View (called tblviewContainer in the following snippet of code)

在我的 viewdidload 方法中,我制作了一个图层,我将把它放在我的视图(tblviewcontainer)上,以便屏幕的顶部和底部的一些是渐变的。

[tblViewContainer addSubview:self.tableView];
[tblViewContainer sendSubviewToBack:self.tableView];

if (!maskLayer)
{
    maskLayer = [CAGradientLayer layer];

    UIColor* outerColorSetup = [UIColor colorWithWhite:1.0 alpha:0.0];
    UIColor* innerColorSetup = [UIColor colorWithWhite:1.0 alpha:1.0];

    CGColorRef outerColor = outerColorSetup.CGColor;
    CGColorRef innerColor = innerColorSetup.CGColor;

    maskLayer.colors = [NSArray arrayWithObjects:
                         (__bridge id )outerColor,
                         (__bridge id)innerColor,
                         (__bridge id)innerColor, 
                         (__bridge id)outerColor, nil];

    maskLayer.locations = [NSArray arrayWithObjects:
                           [NSNumber numberWithFloat:0.01],
                           [NSNumber numberWithFloat:0.04],
                           [NSNumber numberWithFloat:0.8],
                           [NSNumber numberWithFloat:1.0], nil];

    maskLayer.bounds = CGRectMake(0, 0,
                                  self.tableView.frame.size.width,
                                  self.tableView.frame.size.height);

    maskLayer.anchorPoint = CGPointZero;

    tblViewContainer.layer.mask = maskLayer;

}

在我的应用程序中可以旋转,当我在图层打开的情况下这样做时,旋转时非常缓慢/滞后(仅在 ipad 3 上!)。

当我旋转时,我会执行以下操作:(从纵向->横向)

-(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
{
    if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
    {

    }
    else if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {
        _landscape = [[ipad_VideoListViewController_Landscape alloc] initWithNibName:@"ipad_VideoListViewController_Landscape" bundle:nil];
        _landscape.scroolViewContentOffset = scroolViewContentOffset;
         [self.view.layer setRasterizationScale:[UIScreen mainScreen].scale];
          self.view.layer.shouldRasterize = YES;


        NSMutableArray *viewCons = [[[self navigationController]viewControllers] mutableCopy];
        [viewCons removeLastObject];
        [viewCons addObject:_landscape];
        [[self navigationController]setViewControllers:viewCons animated:NO];
    }
}

最糟糕的是,它在 ipad 2 上完美运行,图层处于活动状态,但 ipad 3 似乎无法处理它。甚至似乎我在 ipad 2 上用动画做的事情(有效),不能在 ipad 3 上处理。例如我制作了自己的 tableview 标题单元格/tableview 单元格,如果我在 ipad 3 上使用它们,它们也会滞后。

任何帮助将不胜感激!

【问题讨论】:

  • 添加了以下两行:(to willrotate) [self.view.layer setRasterizationScale:[UIScreen mainScreen].scale]; self.view.layer.shouldRasterize = YES;以下行应该自动旋转: self.view.layer.shouldRasterize = NO;它帮助很小,所以它仍然不顺利。

标签: objective-c ios ipad core-animation calayer


【解决方案1】:

我添加了一些透明图像,并且运行流畅。

不过,如果有人知道为什么这不起作用,我想知道。

必须找到这个解决方案,因为我有最后期限 :)。

感谢迈克尔的评论!

【讨论】:

    【解决方案2】:

    在你的 willRotateToInterfaceOrientation 中尝试rasterizing

    self.view.layer.shouldRasterize = YES;
    

    然后在你的 didRotateToInterfaceOrientation 中:

    self.view.layer.shouldRasterize = NO;
    

    此外,请确保您的图层尽可能不透明。

    【讨论】:

    • 我稍后会尝试,如果有帮助会发布!
    • 它没有用。还是像以前一样不顺畅的旋转。而不是self.view.layer,不应该是tblviewcontainer.layer吗?因为它在那里添加了图层。无论如何,我都尝试了,但没有一个有所作为。 (我也猜想,我也必须在我的横向视图控制器中这样做?我也这样做了!:))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    相关资源
    最近更新 更多