<span id="Label3"></p><p><p>Switching between different interfaces or different views is one of the most common dynamic effects of the application, regardless of which platform the project development, the default view switch is often very monotonous, without any animation, the interface switch is very abrupt. If you use an animated effect to make the interface active, your app will be very dynamic. This will implement the animation effect in the view switching process. The specific implementation is as Follows:</p></p><p><p>(1) This experiment will drag 2 images, not directly into the view controller, but dynamically loaded in the Code. Drag into Main.storyboard after the directory structure is as Follows:</p></p><p><p>。</p></p><p><p><br></p></p><p><p>(2) implement the image and code outlet binding:</p></p><p><p></p></p><pre name="code" class="plain"><pre name="code" class="plain"> @IBOutlet weak var image1:uiimageview! @IBOutlet weak var image2:uiimageview!</pre></pre><br>(3) implement the following code in Viewcontroller:<p><p></p></p><p><p></p></p><pre name="code" class="plain">Import Uikitclass Viewcontroller:uiviewcontroller {@IBOutlet weak var image1:uiimageview! @IBOutlet weak var image2:uiimageview! var Isfirstpic:bool = True//determines Whether it is the first picture; 2 images can be cycled; override func viewdidload () {super.viewdidload () Self.view.addSubview (image1)//load First picture first;} override func didreceivememorywarning () {super.did Receivememorywarning ()//Dispose of any of the resources that can is recreated. } override func Touchesbegan (touches:set<nsobject>, withevent event:uievent) {func complete (v:bool) {//actions performed after each view switch; println ("already Complete") isfirstpic =!isfirstpic} If (isfirstpic) {//the first picture switches to the second picture; Uiview.transitionfromview (image1, toview:image2, duration: 1, options:UIViewAnimationOptions.TransitionFlipFromLeft, completion:complete)} else{//second picture Switch to The first picture;Uiview.transitionfromview (image2, toview:image1, duration:1, options:UIViewAnimationOptions.TransitionFlipFromTop , completion:complete)}}}</pre><br>(4) Note that the uiviewanimationoptions is the option to toggle the animation, you can see the following several options, a total of 8 animation effects: You can try it yourself, there is always a suitable for you.<p><p></p></p><p><p>.<br></p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>iOS Project development--implement view Toggle Animation</p></p></span>
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