Use UIView animation to implement kCATransitionPush from CATransition

Apple recommended using UIView animation blocks for iOS4 and later ( here ), but I really liked my old CATransition with kCATransitionPush effect. How can I implement kCATransitionPush with UIView animation? I see only four types of view transition in the available options (flip left / right, waving up / down)

If I implement it myself, I plan to create a new view and insert it, shifting the old view. I don’t understand why the apple does not include the β€œpush” effect in the UIView animation.

Thanks!

a lion

+4
source share
4 answers

After reviewing your Apple docs, he also says:

Block-based animation methods (e.g. animateWithDuration: animations :) greatly simplify the creation of animations. With a single method call, you specify the animation and options for the animation. However, block-based animations are only available in iOS 4 and later. If your application works in earlier versions of iOS, you should use beginAnimations: context: and the methods of the commitAnimations class to mark the beginning and end of your animations.

I suppose that means they recommend it because it greatly simplifies the creation of animations. He also notes that he will not work with any devices that do not have ios 4. If you know how to use CAAnimation, I will continue to use it. I still use this without any problems:

- (void)switchTwoViews:(UIView *)view1 otherView:(UIView *)view2 direction:(int)directionRL{ view2.frame = CGRectMake(0, 0, 400, 211); visibleView = view2; // remove the current view and replace with view1 [view1 removeFromSuperview]; [currentOptionsView addSubview:view2]; // set up an animation for the transition between the views CATransition *animation = [CATransition animation]; [animation setDuration:0.3]; [animation setType:kCATransitionPush]; if (directionRL == 0) { [animation setSubtype:kCATransitionFromRight]; } else { [animation setSubtype:kCATransitionFromLeft]; } [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [[currentOptionsView layer] addAnimation:animation forKey:@"SwitchToView"]; 

}

+4
source

The documentation refers to the recommendation of block-based UIView animations using older UIView calls beginAnimations and commitAnimations . This has nothing to do with the CAT transition. You can continue to use Core Animation without any worries.

+2
source

Try entering a code to display the view

 -(void)slideViewTransition:(UIView*)slidingView { CATransition *animation = [CATransition animation]; [animation setDuration:0.4]; [animation setType:kCATransitionPush]; [animation setSubtype:kCATransitionFromTop]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [[slidingView layer] addAnimation:animation forKey:nil]; 

}

If you need to hide the view, simply change the value of [animation setSubtype:kCATransitionFromTop] to [animation setSubtype: kCATransitionFromBottom];

I hope this can help you. !!!!

0
source

Here's the Swift function that animates the left / right view according to the given flag:

 func animateSwipe(on view: UIView, left: Bool) { let transition = CATransition() transition.duration = 0.45 transition.type = kCATransitionPush transition.subtype = left ? kCATransitionFromLeft : kCATransitionFromRight transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn) view.layer.add(transition, forKey: nil) // change anything you want on the view in a reload(view: UIView) function reload(view) } 
0
source

All Articles