Question

I ran into a weird problem where the coordinates I am using for CGRectMake function do not seem to be correct. For example:

CGRect screenR = [[UIScreen mainScreen]bounds];
sWidth = screenR.size.width;
sHeight = screenR.size.height;
button.frame = CGRectMake(sWidth-50, sHeight-50, 50, 50);

This sizes my button to be 50x50 in size and places it correct horizontally, but the button show up in the middle of the screen vertically. I don't know what causes the vertical coordinates to show up incorrectly. Please help.

Was it helpful?

Solution

I found that the problem was with having that code within 'viewDidLoad'. Apparently the coordinates of the view are not completely initialized until that view appears and resulted in the weird behaviour I was describing above. Putting the code within 'viewDidAppear' solved my problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top