近期想做一個跑馬燈的效果,於是寫出了如下的跑馬燈效果的代碼。。。但是調試發現,在iOS6下動畫是可以執行的,但是在iOS7下動畫並不執行,沒有達到預期的效果。
[_scrollLabel sizeToFit];
CGRect frame = _scrollLabel.frame;
frame.origin.x = 320;
_scrollLabel.frame = frame;
[UIView setAnimationsEnabled:YES];
[UIView beginAnimations:@"testAnimation" context:NULL];
[UIView setAnimationDuration:10.f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationRepeatCount:999999];
frame = _scrollLabel.frame;
frame.origin.x = -frame.size.width;
NSLog(@"frame orgin:%f",frame.origin.x);
_scrollLabel.frame = frame;
[UIView commitAnimations];
然後在網上查了各種資料,都沒有解決。。。最終發現,我的這個視圖控制器是present模態化視圖,在iOS7下模態化出來的視圖UIView就出現問題了。。。果斷把present換成了push。。。但是push又達不到prensent的效果,於是又模仿present,在push視圖中實現present動畫。代碼如下:
一、push
MCLotteryListViewController *list = [[MCLotteryListViewController alloc]init];
//list.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
// [self presentViewController:list animated:YES completion:^{
//
// }];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:list animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
二、pop
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
轉載請注明,錯誤請指正!