ios - Having trouble launching with scrollview in 'Closed' state -
i using scrollview 2 containers in order add slide out menu tabbed app working on.
when app launched, if user logged in, main page presented , left slide menu closed. however, if user not logged in , has main page via login button, main page presented menu open. cannot figure out how present closed.
in mainviewcontroller func used close menu initially
func closemenu(animated:bool = true){ scrollview.setcontentoffset(cgpoint(x: leftmenuwidth, y: 0), animated: animated) }
in viewdidload call following close menu
dispatch_async(dispatch_get_main_queue()) { self.closemenu(true) }
i using nsnotifications toggle menu open , closed via button on main page. tried post 'togglemenu' notification when login button tapped not work
pfuser.loginwithusernameinbackground(username!, password: password!) { (user: pfuser?, error: nserror?) -> void in if user != nil { print("successful login") dispatch_async(dispatch_get_main_queue(), { () -> void in let viewcontroller:uiviewcontroller = uistoryboard(name: "main", bundle: nil).instantiateviewcontrollerwithidentifier("containerhome") self.presentviewcontroller(viewcontroller, animated: true, completion: nil) nsnotificationcenter.defaultcenter().postnotificationname("togglemenu", object: nil) }) }
i beginner, if left out details apologize.
thanks in advance given.
first, don't need switch main queue in viewdidload()
method. called in main thread (at least os).
you don't want messing sizes, frames, offsets, etc in viewdidload()
method. view hasn't yet been added superview, size , position meaningless @ point.
try calling closemenu()
viewwillappear()
method instead. may still not work, it's closer point want code run. if doesn't work directly there, can delay until after view has updated this:
override func viewwillappear(animated: bool) { super.viewwillappear(animated) dispatch_after(dispatch_time(dispatch_time_now, int64(0.01 * double(nsec_per_sec))), dispatch_get_main_queue()) { self.closemenu(false) } }
or, can play adding call override of viewdidlayoutsubviews()
:
override func viewdidlayoutsubviews() { super.viewdidlayoutsubviews() if menushouldbeclosed { closemenu(false) } }
menushouldbeclosed
boolean property, because you'll need way keep track here.
Comments
Post a Comment