Re: layoutSubviews doesn't always work (iOS 4.3 on iPad Simulator)
Re: layoutSubviews doesn't always work (iOS 4.3 on iPad Simulator)
- Subject: Re: layoutSubviews doesn't always work (iOS 4.3 on iPad Simulator)
- From: Brian Bruinewoud <email@hidden>
- Date: Sun, 19 Jun 2011 13:46:46 +1000
Hi Matt,
My code is based on Apple's sample "ZoomingPDFViewer" which actually replaces the content view after each zoom so that the contents can be drawn crisply rather than blurily scaled. So, this would be an issue in their code, then, but they only have pinching for rescaling, not zoom-to gestures. Or, perhaps, I copied the code incompletely - I'll re-check. Either way, it seems from your comment that I should then be able to move the code snippet below to the location where the view is replaced.
Further, I'm no longer sure that I need to do the view swapping that Apple's code did - I could probably get away with resizing the original view directly. I'll try that later.
As for scrolling when zoomed large - this issue only happened occasionally but it seems to be gone now.
Anyway, now that we're both happy, I wonder why you need the setContentOffset code while I (it seems so far) do not.
Regards,
Brian.
On 19/06/2011, at 13:24 , Matt Neuburg wrote:
>
> On Jun 18, 2011, at 6:50 PM, Brian Bruinewoud wrote:
>
>> Actually, that didn't work for me but it did lead me to find a solution.
>
> Cool!
>
>>
>> In my case, the scroll view's contentSize wasn't being updated correctly.
>> To fix it I wrote the following (translated to your names) in layoutSubviews:
>>
>> sv.contentSize = v.bounds.size;
>
>
> Hmm. Not sure why that should be necessary. The contentSize should not *need* any updating; you should set it once at the outset, and then when you zoom, the zoomable view is transformed and everything just follows as a matter of course. The scroll view compensates in accordance with the transform, automatically. I don't quite get why you're needing to do this.
>
>>
>> As to why its not being update correctly, I don't know. But this did fix two other issues I was having (and, assuming the issue is in your code too) you should be having- namely, when I zoomed big, the scroll view sometimes wouldn't let me scroll to the portions of the content that were off screen.
>> Could you check in your code to see if its the same issue
>
> Well, no, clearly not. If you download and run the project I pointed you to, you'll see there's no problem about scrolling to the offscreen portions of the image when it's zoomed large. m.
>
>
>
>>
>> On 19/06/2011, at 02:05 , Matt Neuburg wrote:
>>
>>> On Sun, 12 Jun 2011 14:30:42 +1000, Brian Bruinewoud <email@hidden> said:
>>>> Hi All,
>>>>
>>>> I have an app that consists of a scroll view subclass which contains a single subview. In the scroll view subclass I override layoutSubviews based on Apple sample code (see below). The intention of layoutSubviews is to centre the subview in the scrollview when the subview is smaller than the scrollview's display area.
>>>>
>>>> There are three circumstances where the layoutSubviews is called but in one of them the visual results are incorrect.
>>>
>>> Funny you should mention this, since I was just experimenting with the same issue. What I ended up doing is setting the contentOffset explicitly after the zoomScale changes.
>>>
>>> https://github.com/mattneub/Programming-iOS-4-Book-Examples/tree/master/p492zoomCentered
>>>
>>> m.
>
> --
> matt neuburg, phd = email@hidden, http://www.apeth.net/matt/
> pantes anthropoi tou eidenai oregontai phusei
> Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
> Programming iOS 4! http://www.apeth.net/matt/default.html#iosbook
> RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
> TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden