简体   繁体   中英

Resizing UIView with UIScrollView subview

I have a big problem concerning the resizing of a derived UIView with a UIScrollView as subview.

In the layoutSubviews message I set the frame of the UIScrollView subview. the UIScrollView contains a UIImageView with a big image which can be moved/pinched and so on. The initial contenSize of the UIScrollView is the initial image size.

So far, so good. Moving and pinching of the image works well. Now I have to change the UIView frame (in my app to maximize the UIView). im doing that in a animation block ( beginAnimations / commitAnimations ). So I set the new frame (which will update the width & height) an then I call [myView layoutIfNeeded] to force the UIScrollView to update its frame in the layoutSubviews message of my view.

The UIView animates correct to its new frame and if the contentOffset of the UIScrollView is currently x 0, y 0 the UIScrollView frame will be updated properly. but here's my problem: if the contentOffset of the UIScrollView is bigger than x 0, y 0 the UIScrollView will "slide in" from upper left to its final position.

I want that the UIScrollView resizes its frame properly with the parents frame and aligns the content (in my case the UIImageView ) right. But how could I achieve that?

after hours of web research i found the solution for this problem:

[UIView setAnimationBeginsFromCurrentState: YES];

this will animate all layers from the current state.

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