Re: Programmatically pinch a UIView
Re: Programmatically pinch a UIView
- Subject: Re: Programmatically pinch a UIView
- From: Quincey Morris <email@hidden>
- Date: Wed, 11 May 2016 14:33:38 -0700
- Feedback-id: 167118m:167118agrif8a:167118stZoP8mteB:SMTPCORP
On May 11, 2016, at 14:14 , Carl Hoefs <email@hidden> wrote:
>
> the UIView that's currently there handles pinch zoom in/out fine.
You should at this point explain what mechanism you’re using to do this.
> Is there a way to programmatically cause a 'pinch zoom out by 10%'?
The result of applying a “pinch” gesture to an app isn’t semantically fixed, and there are at least two straightforward possibilities:
1. You can transform the view. This changes the effective frame, but leaves the bounds untouched, and doesn’t require any changes to drawRect. The scaling is applied to the view *after* drawRect, conceptually.
2. You can scale what you’re doing in your drawing code. This leaves the frame and bounds untouched, but the scale factor will form part of your drawing code’s calculations. You are, in effect, “simulating” zoom.
#1 is usually called zooming (well, “magnification” in NSScrolView, but let’s stick with iOS), and pinching usually zooms, because the functionality for that is built into UIScrollView. A sane person would always zoom (#1) instead of #2 when possible, because its easier to get it right, and you get all the animation decorations (such as over-zoom bounce) for free.
Downsides of #1 in certain scenarios:
— Everything you draw is magnified, which may or may not be the effect you want. For example if you have 1-pt borders on your drawn elements, they’ll actually be 2 pt at 200% (unless of course you choose to draw them as 0.5-pt borders to “undo” the zoom factor).
— Sometimes iOS magnifies the pixels, for efficiency, say. That means a zoomed view (#1) may look a little less precise than a draw-scaled view (#2).
David Duncan’s answer assumed you were trying to achieve #1, because he is (apparently) a sane person.
_______________________________________________
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