简体   繁体   中英

ScrollView offsets when superview is setframe?! (iphone)

So i have a View and a scroll view inside that view. I call a

[View setFrame:CGRectMake(55,70,260,420)];

i put a

NSLog(@"%f %f",scrollview.frame.origin.x, scrollview.frame.origin.y);

before and after the setFrame and it reads 6,112 and then 6,172. 112 is correct, i have no idea where the 60 comes from. i searched 60 in my implementation file, and there is nothing that could affect the y at all. is there some rule with doing a setframe when there is a view inside that view?

Thanks

If you take a look at the UIView reference, the frame property states

frame

The frame rectangle, which describes the view's location and size in its superview's coordinate system. @property(nonatomic) CGRect frame

Discussion

This rectangle defines the size and position of the view in its superview's coordinate system. You use this rectangle during layout operations to size and position the view. Setting this property changes the point specified by the center property and the size in the bounds rectangle accordingly. The coordinates of the frame rectangle are always specified in points.

So i guess when you NSLog the frame for scrollview it is displayed based on the coordinates of the superview. The second NSLog shows different because the superview's coordinate system has changed.

I fixed this by making the scrollview in my code instead of doing it through the XIB. the scrollview is created after the setFrame and addSubView of the parent View

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM