Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 8, 2010, 06:07 PM   #1
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Zooming a UIScrollView without a CATiledLayer

I've been trying to figure out how to zoom a UIScrollView without using CATiledLayer. Almost every example I've found and Apple's documentation says you should use CATiledLayer since it handles the automatic zooming for you and you just need to draw your content like normal via the layer's delegate. If you don't use CATiledLayer you get simply a blurred image of your layer/view.

However if you try to add sublayers to CATiledLayer, you don't get the nice sharpened scaling automatically (CAShapeLayer does work though). The other problem with CATiledLayer is you have very little control over it.

Lots of various people have played around with altering the transform which I didn't have much success with (could be due to iOS 4 changes?).

However, I think I have found a solution which would make sense based on how Apple's CATiledLayer works and CAShapeLayer's documentation. You just need to redraw the layer's image at the scaled value into a CGImage (CGBitmapContext) and set that as the layer's contents.

It's working well right now in the simulator, but I feel like there should be a better way to go about it. What do you guys think? I can post a sample project.
kainjow is offline   0 Reply With Quote
Old Jul 9, 2010, 04:58 PM   #2
althecoug
macrumors newbie
 
Join Date: Jul 2010
Hi kainjow

Please post a project. Also, do you have a project that does zooming a UIScrollView with a CATiledLayer using CG drawing elements (e.g., line art, text) (as opposed to an image)? I have yet to find an sample code that does this combination correctly.

Thanks
althecoug is offline   0 Reply With Quote
Old Jul 24, 2010, 02:51 PM   #3
a9702466
macrumors newbie
 
Join Date: Jul 2010
Beware! Using the contents property always needs a lot of memory for higher zoomscales. This Memory is aquired by the View and you cannot avoid this only by Tiling the content. It seem that the layer allocates memory for an images of the current zoomScale and draws the given image in it. It doesn't use the image directly.
a9702466 is offline   0 Reply With Quote
Old Jul 24, 2010, 04:50 PM   #4
kainjow
Thread Starter
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Quote:
Originally Posted by althecoug View Post
Also, do you have a project that does zooming a UIScrollView with a CATiledLayer using CG drawing elements (e.g., line art, text) (as opposed to an image)? I have yet to find an sample code that does this combination correctly.
There's nothing special to it. Just draw into the layer's context via the delegate method (overriding the CALayer method may also work). It will get properly scaled for you automatically. However if you want to *not* draw scaled, you need to apply a transform that essentially cancels the existing zoom transform and then apply the scale to your drawing manually. This is what I'm currently doing along with CATiledLayer to better handle how the zoomed drawing renders. I may post a sample later.

Quote:
Originally Posted by a9702466 View Post
Beware! Using the contents property always needs a lot of memory for higher zoomscales. This Memory is aquired by the View and you cannot avoid this only by Tiling the content. It seem that the layer allocates memory for an images of the current zoomScale and draws the given image in it. It doesn't use the image directly.
yea that is the problem when rolling your own without CATiledLayer. I decided to just use CATiledLayer for the time being but may end up having to roll my own version that provides greater control of how and when the tiles get generated and cached.
kainjow is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: UIScrollView does not scroll a UIImageView Tex-Twil iPhone/iPad Programming 4 Nov 20, 2013 06:57 AM
UITableView in UIScrollview IDMah iPhone/iPad Programming 4 Aug 4, 2013 11:25 AM
Subview is not working in UIScrollView Narendar Singh iPhone/iPad Programming 0 Nov 23, 2012 07:49 AM
Zooming one application only? cameronjpu OS X 10.8 Mountain Lion 0 Oct 24, 2012 05:21 PM
UIScrollView silly questions... animefx iPhone/iPad Programming 3 Jul 2, 2012 04:10 PM

Forum Jump

All times are GMT -5. The time now is 11:00 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC