ios - View doesn't display all subviews when viewDidAppear called again -
goal of task display n-times subview in superview, , when open tab (i have tab bar controller) subviews must redraw.
now, when open application @ first time views draws in each other correctly. if open tab , again open previous subviews must redraw but, redraws first subview or two.. maybe constraints..
method draw subviews invoke in viewdidappear.
here code:
import uikit import chameleonframework class drawingvc: uiviewcontroller { let defaults = userdefaults.standard let countofviewskey = "countofviews" var viewscount : int { get{ return int(defaults.object(forkey: countofviewskey) as! string) ?? 0 } } var screenheight : int { get{ return int(uiscreen.main.bounds.height) } } var tabbarheight : int { get{ return int((tabbarcontroller?.tabbar.frame.size.height)!) } } var screenwidth : int { get{ return int(uiscreen.main.bounds.width) } } func drawviews(count : int, view : uiview){ let inscribedview = uiview() inscribedview.translatesautoresizingmaskintoconstraints = false let sizeconstant = ((screenwidth / 2 ) / viewscount ) view.addsubview(inscribedview) view.addconstraint(nslayoutconstraint.init(item: inscribedview, attribute: .top, relatedby: .equal, toitem: view, attribute: .top, multiplier: 1, constant: cgfloat(sizeconstant))) view.addconstraint(nslayoutconstraint.init(item: inscribedview, attribute: .trailing, relatedby: .equal, toitem: view, attribute: .trailing, multiplier: 1, constant: -cgfloat(sizeconstant))) view.addconstraint(nslayoutconstraint.init(item: inscribedview, attribute: .bottom, relatedby: .equal, toitem: view, attribute: .bottom, multiplier: 1, constant: -(cgfloat)(count == viewscount ? tabbarheight + sizeconstant : sizeconstant))) view.addconstraint(nslayoutconstraint.init(item: inscribedview, attribute: .leading, relatedby: .equal, toitem: view, attribute: .leading, multiplier: 1, constant: cgfloat(sizeconstant))) inscribedview.backgroundcolor = randomflatcolor() if count == 0 { return } var timer = timer.scheduledtimer(withtimeinterval: 0.3, repeats: false) { tim in return self.drawviews(count: count - 1, view: view.subviews.first!) } } override func viewdidload() { super.viewdidload() print(viewscount) // additional setup after loading view. } override func viewdidappear(_ animated: bool) { super.viewdidappear(animated) drawviews(count: viewscount, view: view) print(viewscount) } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } }
wiki
Comments
Post a Comment