Autoresizing UIViews for a PDF viewer
I'm trying to get autoresizing to work with a PDF viewer I have built for iPad.
My view structure consists of:
Scroll view
Document view
Page view
Page view
Page view
As demonstrated in this diagram: http://i.stack.imgur.com/unV4J.png
I don't have a problem with displaying the PDF pages. Let's say for the purposes of this question that each page is a UIImageView.
To create the view I load all the pages one by one, and set the frames so they are the correct size and have a 10px spacing between them. Then I set the Document View frame to be the total size of all the pages. I then add the document view to the scroll view. This works fine.
The problem is with autoresizing. I want the width of the document view (and the page views inside it) to scale as the scroll view width scales. The document view and the pages obviously need to maintain their aspect ratio, so the width and height need to be fle开发者_JS百科xible. However, if I make the page height flexible, the page frame height becomes that of the document view.
I've played around for hours now trying to get this to lay out properly, but I've had no success. Previously I have just updated the frames on rotation but it would be nice to get this working with the smooth resizing.
I solved this programmatically.
First I tried to use the layoutSubviews UIView method to reposition the subviews when resized. However this only occured once at the beginning of an animation (Using MGSplitViewController, it might be different in other situations), so instead I overrode the setFrame method to reposition the subviews there. This works great and now my views smoothly animate to where they should be.
If anyone else can help me with using autoresizing then I would consider that a better answer, but for the time being I'm happy with this solution.
精彩评论