IOS project development practice-achieve view switching Animation

Source: Internet
Author: User

IOS project development practice-achieve view switching Animation

Switching between different interfaces or views is one of the most common dynamic effects of applications. No matter which platform is used for project development, default view switching is often monotonous, without any animation, the interface switching is also very abrupt. If you use animated effects to make the interface active, your App will be very dynamic. The animation effect during the view switching process will be implemented here. The specific implementation is as follows:

(1) In this experiment, two images will be dragged into the code instead of being directly placed in the View Controller. The directory structure after being dragged to Main. storyboard is as follows:

.

 

(2) bind the image to the Code Outlet:

 

    @IBOutlet weak var image1: UIImageView!    @IBOutlet weak var image2: UIImageView!

(3) implement the following code in ViewController:

 

 

Import UIKitclass ViewController: UIViewController {@ IBOutlet weak var image1: UIImageView! @ IBOutlet weak var image2: UIImageView! Var isFirstPic: Bool = true // determine whether the image is the first one; enable two images to switch cyclically; override func viewDidLoad () {super. viewDidLoad () self. view. addSubview (image1) // first load the first image;} override func didReceiveMemoryWarning () {super. didReceiveMemoryWarning () // Dispose of any resources that can be recreated .} override func touchesBegan (touches: Set
 
  
, WithEvent event: UIEvent) {func complete (v: Bool) {// The operation executed after each view switch; println (Already Complete) isFirstPic =! IsFirstPic} if (isFirstPic) {// switch the first image to the second image; UIView. transitionFromView (image1, toView: image2, duration: 1, options: UIViewAnimationOptions. transitionFlipFromLeft, completion: complete)} else {// switch the second image to the first image; UIView. transitionFromView (image2, toView: image1, duration: 1, options: UIViewAnimationOptions. transitionFlipFromTop, completion: complete )}}}
 

(4) Note that UIViewAnimationOptions is the option to switch the animation. You can see multiple options in it. There are 8 animation effects in total: You can try it by yourself. There is always one that suits you.

 

.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.