2012-09-07 42 views
1

林目前正在對一個通用的應用程序時,使得它非常laggy,而在我的視圖控制器我有以下XIB之一:iPad應用程序 - 的CALayer旋轉

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; 

} 

在我的應用程序,可以旋轉,當我做到這一點與該層上,這是非常慢/ laggy當我轉動(僅在iPad 3!)。

當我轉動i執行以下操作:(從縱向狀態>橫向)

-(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上使用它們。

任何幫助,將不勝感激!

+0

添加了以下兩行:(要旋轉) [self.view.layer setRasterizationScale:[UIScreen mainScreen] .scale]; self.view.layer.shouldRasterize = YES; 而下面的行應該去掉: self.view.layer.shouldRasterize = NO; 它幫助很少,所以它仍然不順利。 – Lasse

回答

1

我增加了一些透明的圖像,而它的運行平穩。

不過,如果有人知道爲什麼這不起作用,我想知道。

必須找到這個解決方案,因爲我有一個截止日期:)。

並感謝評論邁克爾!

0

嘗試rasterizing在willRotateToInterfaceOrientation:

self.view.layer.shouldRasterize = YES; 

,然後在didRotateToInterfaceOrientation:

self.view.layer.shouldRasterize = NO; 

此外,還要確保你的層是不透明的,其中可能的。

+0

我會稍後再試,如果有幫助,會發布! – Lasse

+0

它沒有工作。仍然像以前那樣不平順的旋轉。而不是self.view.layer,它不應該是tblviewcontainer.layer?因爲它在那裏添加了圖層。從來沒有,我嘗試了兩種,並沒有一個有所作爲。 (我也猜測,我必須在我的景觀視圖控制器中這也是我也做的!:)) – Lasse