A simple jump show sub Controller for Addchildviewcontroller

Source: Internet
Author: User

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

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.