In iOS development, we typically use custom transitions animations when we model another controller.
We can actually customize some transition animations. Achieve a different transition effect.
The steps are as follows: (Photobrowser is the target controller)
1. in the source controller, set the destination controller's transition agent to Self
1 // setting up the Model transition Agent 2 photobrowser.transitioningdelegate = self
2. Set the model type of the target controller at the same time
1 // Set Model type 2 Photobrowser.modalpresentationstyle=uimodalpresentationstyle.custom
3. Define a variable record transitions or exits (true for transitions, false for exit
1 false
4. Set jump in Source controller, set off in target controller (animation to select true)
1 true inch }2 dismissviewcontrolleranimated (true) {Svprogresshud.dismiss ()}
5. The source controller adheres to two agents
Uiviewcontrollertransitioningdelegate,
Uiviewcontrolleranimatedtransitioning
6. Source Controller implements 2 proxy methods
1Func Animationcontrollerforpresentedcontroller (Presented:uiviewcontroller, Presentingcontroller presenting: Uiviewcontroller, Sourcecontroller source:uiviewcontroller), uiviewcontrolleranimatedtransitioning?{2 //Transitions3Ispersent =true4 //The source Controller is itself responsible for transitions5return Self6 }7 8Func Animationcontrollerfordismissedcontroller (Dismissed:uiviewcontroller) Uiviewcontrolleranimatedtransitioning?{9 Ten //Exit OneIspersent =false A //The source Controller is itself responsible for transitions -return Self -}
7. Source controller to implement 2 proxy methods
1 //transition Time2Func transitionduration (transitioncontext:uiviewcontrollercontexttransitioning)Nstimeinterval3 4 //transition Context, responsible for the specific contents of the transition animation5 func animatetransition (transitioncontext:uiviewcontrollercontexttransitioning) {6 //Transition Animations7ifispersent{8ifLet Toview =Transitioncontext.viewforkey (uitransitioncontexttoviewkey) {9//Add Containerview () to the puppet view (the picture shown during animation)TenTransitioncontext.containerview (). Addsubview (self.persenteddummyview!) OneToview.frame =Cgrectzero ASelf.persenteddummyview?. frame =Cgrectzero - -Uiview.animatewithduration (2.0, animations: {(), Voidinch theSelf.persenteddummyview?. frame =Transitioncontext.containerview (). Frame -Toview.frame =Uiscreen.mainscreen (). Bounds -}, Completion: {(_), Voidinch -//removing the puppet view +Self.persenteddummyview?. Removefromsuperview () -//Add a view to display normally + Transitioncontext.containerview (). Addsubview (Toview) A//End atTransitioncontext.completetransition (true) - }) - } - } -//Exit Animation -if!ispersent{ inifLet Fromview =Transitioncontext.viewforkey (uitransitioncontextfromviewkey) { - to//Hide the target controller +Let Fromvc = Transitioncontext.viewcontrollerforkey (Uitransitioncontextfromviewcontrollerkey) as!Hjcphotobrowserviewcontroller -FromVC.view.hidden =true the //get a snapshot of Fromvc *Let dummy = FromVC.collectionView.visibleCells (). last!. Snapshotviewafterscreenupdates (false) $//put the puppet view into ContainerviewPanax Notoginseng Transitioncontext.containerview (). Addsubview (dummy) -//Performing animations theUiview.animatewithduration (2.0, animations: {(), Voidinch +Dummy.frame =Cgrectzero A}, Completion: {(_), Voidinch the//removing the puppet view + Dummy.removefromsuperview () -//End $Transitioncontext.completetransition (true) $ }) - } - } the } - Wuyi the}
Custom transition animations in "Swift" iOS development