我有一個奇怪的錯誤,我似乎無法弄清楚。我創建了一個閃亮的動畫,它完美的工作,但由於某種原因,當我通過UINavigationController或UITabView導航到另一個視圖時(奇怪的是模態視圖不會影響它)停止。任何想法爲什麼,以及如何確保動畫不會停止?使用UINavigationController或UITabView時動畫停止
UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[whiteView setBackgroundColor:[UIColor whiteColor]];
[whiteView setUserInteractionEnabled:NO];
[self.view addSubview:whiteView];
CALayer *maskLayer = [CALayer layer];
maskLayer.backgroundColor = [[UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.0f] CGColor];
maskLayer.contents = (id)[[UIImage imageNamed:@"ShineMask.png"] CGImage];
// Center the mask image on twice the width of the text layer, so it starts to the left
// of the text layer and moves to its right when we translate it by width.
maskLayer.contentsGravity = kCAGravityCenter;
maskLayer.frame = CGRectMake(-whiteView.frame.size.width,
0.0f,
whiteView.frame.size.width * 2,
whiteView.frame.size.height);
// Animate the mask layer's horizontal position
CABasicAnimation *maskAnim = [CABasicAnimation animationWithKeyPath:@"position.x"];
maskAnim.byValue = [NSNumber numberWithFloat:self.view.frame.size.width * 9];
maskAnim.repeatCount = HUGE_VALF;
maskAnim.duration = 3.0f;
[maskLayer addAnimation:maskAnim forKey:@"shineAnim"];
whiteView.layer.mask = maskLayer;
什麼方法執行這個代碼? – cduhn
此代碼是自定義UIViewController對象的一部分。該對象在另一個視圖中被初始化,並從該視圖調用該方法。 – Rob