隨機我的應用程序根本不會動畫。我的應用程序有一個聲音欄,每0.1秒更新一次動畫。通常,當我啓動應用程序時,動畫將會非常漂亮地運行,但通常在我轉換到另一個視圖控制器(通過setViewControllers
)後,隨機點會突然停止動畫。這不只是這個動畫,而是我的應用程序中的所有動畫,不包括setViewControllers
。有時UIView animateWithDuration立即發生
這裏是我的代碼,我叫setViewControllers
:
- (void)goToController:(GeneralViewController *)vc animate:(BOOL)animated sub:(BOOL)sub{
if(animated){
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray *viewController = [NSMutableArray arrayWithArray:[delegate.navController viewControllers]];
if(viewController.count > 0){
viewController[0] = vc;
}else{
[viewController addObject:vc];
}
CATransition* transition = [CATransition animation];
transition.duration = 0.2;
transition.type = kCATransitionPush;
if(sub)
transition.subtype = kCATransitionFromRight;
else
transition.subtype = kCATransitionFromLeft;
[delegate.navController.view.layer addAnimation:transition forKey:kCATransition];
[delegate.navController setViewControllers:viewController animated:FALSE];
self.colorStyle = MusicPlusColorStyleLight;
}else{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray *viewController = [NSMutableArray arrayWithArray:[delegate.navController viewControllers]];
if(viewController.count > 0){
viewController[0] = vc;
}else{
[viewController addObject:vc];
}
[delegate.navController.view.layer removeAnimationForKey:kCATransition];
[delegate.navController setViewControllers:viewController animated:FALSE];
}
}
下面是我用動畫的聲音吧的代碼:
[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationCurveLinear | UIViewAnimationOptionBeginFromCurrentState
animations:^{
meterViewColor.frame = CGRectMake(0, (meterView.frameSizeHeight - (level*meterView.frameSizeHeight)), meterView.frameSizeWidth, (level*meterView.frameSizeHeight));
}
completion:nil];
我已經檢查和代碼是在主運行線。 CPU平均約爲10%,內存爲25 MB。所以我對於它爲什麼有時會停止工作感到非常困惑。有沒有其他人經歷過這個?
更新:對不起,但我發佈的答案是不正確的。它仍然沒有工作。我已刪除我的答案和波紋管連接它:
當創建我加入了動畫:
[transition setDelegate:self];
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.navController.view removeTransition];
}
- (void) removeTransition {
if (!CGAffineTransformIsIdentity(self.transform)) {
self.transform = CGAffineTransformIdentity;
}
}
是你從故事板或筆尖加載任何視圖控制器? – Milo 2014-09-02 00:33:52
@Milo沒有一切都是基於代碼的 – kezi 2014-09-02 00:42:45
如果設置的框架或其他代碼點擊錯誤,那麼動畫立即完成。您需要註銷並確保所有幀值都符合您的預期。如果您在完成時退出'完成',我會打賭它是'不'。在框架代碼中可能有些不好的數學。 – 2014-09-02 01:30:11