ios - UIView center property is giving unexpected result -


i trying design screen programmatically. first, setup navigation bar. after add table view , after add plain uiview. having trouble while using .center property of last added uiview. want add uiactivityindicatorview view. code follows (using default height , width of large white activity indicator, 37pt each):

func setupactivityview() {     let screen = uiscreen.mainscreen().bounds     let view = uiview(frame: cgrectmake(0.0, self.navbar.frame.height, screen.width, uiscreen.mainscreen().bounds.height-self.navbar.frame.height))     view.backgroundcolor = uicolor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.80)     //view.hidden = true     self.activityview = view     self.view.addsubview(view)      let spinner = uiactivityindicatorview(activityindicatorstyle: .whitelarge)     spinner.startanimating()     spinner.hideswhenstopped = true     self.spinner = spinner     /*point:1*/ //spinner.center = view.center     /*point:2*/ //spinner.frame.size = cgsizemake(37.0, 37.0)     /*point:3*/ spinner.frame = cgrectmake((view.frame.width/2) - 18.5, (view.frame.height/2) - 18.5, 37.0, 37.0)     view.addsubview(spinner) } 

in above code, if see carefully, have commented point:1 point:2 , using point:3. gives me following result (which correct , expected):

enter image description here

now, when use point:1 point:2 , comment point-3 following:

func setupactivityview() {     let screen = uiscreen.mainscreen().bounds     let view = uiview(frame: cgrectmake(0.0, self.navbar.frame.height, screen.width, uiscreen.mainscreen().bounds.height-self.navbar.frame.height))     view.backgroundcolor = uicolor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.80)     //view.hidden = true     self.activityview = view     self.view.addsubview(view)      let spinner = uiactivityindicatorview(activityindicatorstyle: .whitelarge)     spinner.startanimating()     spinner.hideswhenstopped = true     self.spinner = spinner     /*point:1*/ spinner.center = view.center     /*point:2*/ spinner.frame.size = cgsizemake(37.0, 37.0)     /*point:3*/ //spinner.frame = cgrectmake((view.frame.width/2) - 18.5, (view.frame.height/2) - 18.5, 37.0, 37.0)     view.addsubview(spinner) } 

i following result (which , guess, wrong , unexpected):

enter image description here

so difference 2 approaches , going wrong here? understanding of 2 approaches wrong? if yes happens here?

  1. viewdidload

    in method view width , height not properly. can print view width , height know reason.

  2. viewdidappear

    viewdidappear called when view visible, code have place here //now check it


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -