CATransition animation taking long time in iOS

515 Views Asked by At

I added animation to push one controller to another controller.here is my code to push view.this animation is taking 2 second in iPhone 5S and taking 5 seconds in iPhone 5.i am not able to figure out what is exact issue.i want this animation for 1 second.here is my code.

 DetailVC *detailObj = [[DetailVC alloc] initWithNibName:@"DetailVC" bundle:nil];
 detailObj.dataGift = data;


        detailObj.view.transform =  CGAffineTransformScale(CGAffineTransformIdentity, 2.0, 2.0);
        [UIView animateWithDuration:1.0
                         animations:^{
                             CATransition* transition = [CATransition animation];
                             transition.duration = 0.75;
                             transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
                             transition.type = kCATransitionFade;
                             [self.navigationController.view.layer addAnimation:transition forKey:nil];
                            [self.navigationController pushViewController:detailObj animated:false];

                             detailObj.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);
                         } completion:^(BOOL finished) {

                         }];
      });
2

There are 2 best solutions below

12
Prashant Tukadiya On

You are performing animation inside animation block so your duration is increased

Replace your code with

 DetailVC *detailObj = [[DetailVC alloc] initWithNibName:@"DetailVC" bundle:nil];
 detailObj.dataGift = data;
 detailObj.view.transform =  CGAffineTransformScale(CGAffineTransformIdentity, 2.0, 2.0);


CATransition* transition = [CATransition animation];
transition.duration = 0.75;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:detailObj animated:false];

detailObj.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);

And make sure you perform that in Main Queue

Hope it is helpful

0
Krutarth Patel On

issue was in home detail screen,heavy task was happening in viewdidload.i check line by line,commenting each line in view didload which activity is taking more time.and i put time consuming activity in main thread and my issue is resolved.

here is my code of animation

 gameDetailObj.view.transform =  CGAffineTransformScale(CGAffineTransformIdentity, 2.0, 2.0);
        [UIView animateWithDuration:1.0
                         animations:^{

                             [self.navigationController pushViewControllerSafetly:gameDetailObj animated:NO];

                             gameDetailObj.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);
                         } completion:^(BOOL finished) {

                         }];