Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-07-2011, 07:59 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 2
newUser_ is on a distinguished road
Default Help - Scaling CAShapeLayer (i.e. path) in UIScrollView

Hi guys, I have a problem and I hope you can help me with it. This is for iPad by the way.

I have a UIScrollView, UIImageView, CAShapeLayer, and a CGMutablePathRef.

1- So, I loaded an Image in the UIImageView

2- Then, I parsed all the paths from a file, then added them to CAShapeLayer(s) i.e. each CAShapeLayer is a path.

3- Then I added all the CAShapeLayer(s) to the UIImageView.layer

4- I did step 3 so I can use the function below to return the view that holds the image and the paths. This helps scaling the paths and the image together.

- (UIView *)viewForZoomingInScrollView: (UIScrollView *)scrollView
{
return myUIImageView;
}


5- Then I added the UIImageView to the UIScrollView.

6- Then I subclassed the UIScrollView so I can get touchesBegan etc..

*Note: All my touch events such as the touchesBegan are able to detect all the paths when I click on them by using CGPathContainsPoint(aLayer.path, &transf, touchPoint, NO). Also, I can scroll in the view after zooming as well and it works fine.

*Now The Problem Is:

- Whenever I zoom in/out, the CAShapeLayer(s) get scaled fine, but it seems that the (original coordinates of the paths) do not get scaled, or at least that is what I believe. I am saying this because when I click on the CAShapeLayer(s), they do not respond, but when I click on their original place or close to where the CAShapeLayer shown, I get the CAShapeLayer responding.

- I tried to get all the CAShapeLayer(s) into an array, erase them from the view, and add them again, but the did not change anything. I tried other stuff as well such as trying to scale the CAShapeLayer(s) separately, by adding the CAShapeLayer(s) to the UIScrollView instead of the UIImageView. Then I get the current applied scale and apply it to the all the CAShapeLayer(s), but that did not produce a good result.

-Check the attached screenshots. I hope they help.

I hope you can help me with it, thanks in advance.
Attached Images
File Type: jpg BeforeScaling.jpg (87.9 KB, 5 views)
File Type: jpg AfterScaling.jpg (92.0 KB, 3 views)

Last edited by newUser_; 08-12-2011 at 08:24 AM. Reason: Clearer Title and more specific.
newUser_ is offline   Reply With Quote
Old 08-12-2011, 02:22 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 2
newUser_ is on a distinguished road
Default

I guess I'll answer it after I finally found out. To those who may get stuck like me, simply do this.

Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{
    for (UITouch *touch in touches) 

    {
          // The [self.view.subviews objectAtIndex:0]] is the view that I want to check whether the CAShapedLayer is touched or not.
          CGPoint touchPoint = [self.view convertPoint:[touch locationInView:self.view] toView:[self.view.subviews objectAtIndex:0]];
    }

}

More Details:

When the the scroll view scales a view, it doesn't change the internal coordinate system of that view, only its external coordinate system. Since hit-testing the CAShapeLayer in the internal coordinate system of the image view, you should convert your touch points to that view's coordinate system before doing the hit testing.

Last edited by newUser_; 08-12-2011 at 08:29 AM.
newUser_ is offline   Reply With Quote
Reply

Bookmarks

Tags
cashapelayer, cgmutablepathref, scale, uiimageview, uiscrollview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 397
14 members and 383 guests
7twenty7, blasterbr, buggen, chiataytuday, dedeys78, dre, fiftysixty, HemiMG, jimmyon122, jonathandeknudt, LEARN2MAKE, pungs, tymex, UMAD
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:04 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0