Tho Nguyen Tho Nguyen - 4 months ago 20
iOS Question

Add subView immediately after view presented

I have 2 view A and B.
At view A

presentViewController(viewB, animation: true) {
NSNotificationCenter.defautCenter.postNotificationName("addButton")
}


At view B:
var masterView:UIView!

func addButton(notification: NSNotification){
var button:UIButton!
button.frame = masterView.caculator // set frame for button
self.addSubview(button)
}


When view B finished animation on simulator( go from Bottom). Button added after delay 0.3s.

Following some document, when animation finish, method viewDidAppear called. i tried this way. But as I saw, button added after animation finish 0.3s

How to addButton immediately when animation finish?
Thank you!

Answer

I have solved it. Because in viewDidAppear, this method was called when all Layout is loaded. So we need implement add my button in LayoutSubview Method.