The use of Addchildviewcontroller can save memory effectively, and can easily display the sub-controller you want to display, the following is a simple implementation of Swift jump process.
Class first : uiviewcontroller {
//two,three, four for three controllers respectively
var : Both ?
var three: three?
var four : three?
//child Test
var addchildvcclick: UIButton?
var currentc: uiviewcontroller?
override func viewdidload () {
Super. Viewdidload()
self. View. BackgroundColor = uicolor. Bluecolor()
self. Setupsubview()
}
func Setupsubview () {
Addchildvcclick = UIButton()
self. View. Addsubview(addchildvcclick!)
Addchildvcclick?. frame = cgrectmake(Max, +, +)
Addchildvcclick?. backgroundcolor = uicolor. Greencolor()
Addchildvcclick?. userinteractionenabled = true
Addchildvcclick?. addTarget(self, action: "AddChild", forControlEvents:. TouchDown)
}
// Click the button to implement the child controller add
func addChild () {
Print("Add Child")
both = ()
self. Addchildviewcontroller(both!)
three = three()
self. Addchildviewcontroller(three!)
Four = three()
four!. View. BackgroundColor = uicolor. Browncolor()
self. Addchildviewcontroller(four!)
The Child controller is only displayed if the view of the sub-controller is added
self. View. Addsubview(four!). view)
if let f = four {
// Add a button to the fourth Controller and click to implement the Sub controller switch
Addchildvcclick?. frame = cgrectmake(Max, +, +)
Addchildvcclick?. backgroundcolor = uicolor. Bluecolor()
Addchildvcclick?. userinteractionenabled = true
Addchildvcclick?. addTarget(self, action: "Changeviewcontroller", forControlEvents:. TouchDown)
F.view. Addsubview(addchildvcclick!)
CurrentC = f // must be set Currenc(Global properties)
}
}
func Changeviewcontroller () {
Print("Changeviewcontroller")
a. View. BackgroundColor = uicolor. Redcolor()
self. Transitionfromviewcontroller(CurrentC!, Toviewcontroller: both!, Duration: 1, Options:. Transitioncurlup, animations: {(), Void in
Print("animations")
}) {(COM), Void in
Print("com")
self. CurrentC = self. a real jump here, simple and convenient
the// jump effect is determined by the options parameter
}
}
}
A simple jump show sub Controller for Addchildviewcontroller