我正在制作一个使用 GameKit 来报告成就的通用应用程序。这在 iPhone 上运行时效果很好 - 全屏模式 Game Center 视图控制器向上滑动并要求我在应用程序启动时登录。
然而,当我在 iPad 上运行这个应用程序时,GC 视图控制器的窗口 iPad 版本会向上滑动,但一旦停止,屏幕就会略微变灰,我无法与模态视图控制器或其他任何东西进行交互。
我已将问题缩小到用于应用程序窗口背景的滚动效果,特别是在将动画子层添加到窗口层时:
-(void)startGridScroll
{
//Create layer and pattern it with the grid image as a color
UIImage * gridImage = [UIImage imageNamed:@"scrolling_grid.png"];
UIColor * gridPattern = [UIColor colorWithPatternImage:gridImage];
CALayer * gridLayer = [CALayer layer];
[gridLayer setZPosition:-1];
gridLayer.backgroundColor = gridPattern.CGColor;
//Transform the image on its Y-axis
gridLayer.transform = CATransform3DMakeScale(1.0, -1.0, 1.0);
gridLayer.anchorPoint = CGPointMake(0.0,1.0);
CGSize scrollSize = self.window.bounds.size;
//Make the layer's frame twice the width of the image
gridLayer.frame = CGRectMake(0.0, 0.0, gridImage.size.width + scrollSize.width, scrollSize.height);
//*******This is the line causing the issue******
[self.window.layer addSublayer:gridLayer];
//Define start position and end coordinates for grid image
CGPoint start = CGPointZero;
CGPoint end = CGPointMake(-gridImage.size.width, 0);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fromValue = [NSValue valueWithCGPoint:start];
animation.toValue = [NSValue valueWithCGPoint:end];
animation.repeatCount = HUGE_VALF;
//Set animation duration and begin
animation.duration = 7.0;
[gridLayer addAnimation:animation forKey:@"position"];
}
我两次调用此方法:最初在application: didFinishLaunchingWithOptions
方法中,然后在applicationDidBecomeActive
方法中。消除一个电话或另一个没有帮助。如果我将它们都注释掉,Game Center 登录视图控制器会向上滑动并正常工作。
我假设正在发生某种与层相关的问题。有小费吗?