ios - Navigate to New View Controller after Animation is Completed in Swift 3.0 -


i have (2) goals:

  1. example #1: navigate original view controller new secondviewcontroller after following animation completed in swift 3.0 (i.e. user not have press button , app moves secondviewcontroller after animation completed)

  2. example #2: navigate original view controller new secondviewcontroller after time delay of 5 seconds in swift 3.0 (i.e. user not have press button , app moves secondviewcontroller after timer reaches 5 seconds - no animation involved in second example, timer)

here code example #1:

import uikit  class viewcontroller: uiviewcontroller {  @iboutlet weak var imageview: uiimageview!  override func viewdidload() {     super.viewdidload()      var imagesname = ["image_1","image_2","image_3","image_4","image_5","image_6","image_7","image_8","image_9","image_10","image_11","image_12","image_13","image_14","image_15"]      var images = [uiimage]()      in 0..<imagesname.count{          images.append(uiimage(named: imagesname[i])!)     }      imageview.animationimages = images     imageview.animationduration = 1.0     imageview.startanimating()  // perhaps here can fire code programatically move new view controller after animation completed      }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }   } 

here xcode setup:

enter image description here

use dispatchqueue.main.asyncafter.

edited

set storyboard id secondviewcontroller.

enter image description here

example #1:

... imageview.animationrepeatcount = 1 // <-- here imageview.startanimating()  dispatchqueue.main.asyncafter(deadline: .now() + imageview.animationduration) {     let secondviewcontroller = self.storyboard?.instantiateviewcontroller(withidentifier: "secondviewcontroller")     self.show(secondviewcontroller, sender: nil) } 

example #2:

... imageview.animationrepeatcount = 1 // <-- here imageview.startanimating() dispatchqueue.main.asyncafter(deadline: .now() + 5.0) {     let secondviewcontroller = self.storyboard?.instantiateviewcontroller(withidentifier: "secondviewcontroller")     self.show(secondviewcontroller, sender: nil) } 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -