Is it good choice to move a Sublayer around a view using UIPanGestureRecognizer?

Posted by Pranjal Bikash Das on Stack Overflow See other posts from Stack Overflow or by Pranjal Bikash Das
Published on 2012-09-04T07:19:47Z Indexed on 2012/09/04 15:39 UTC
Read the original article Hit count: 210

I have a CALayer and as sublayer to this CALayer i have added an imageLayer which contains an image of resolution 276x183.

I added a UIPanGestureRecognizer to the main view and calculation the coordinates of the CALayer as follows:

- (void)panned:(UIPanGestureRecognizer *)sender{

        subLayer.frame=CGRectMake([sender locationInView:self.view].x-138, [sender locationInView:self.view].y-92, 276, 183);

}

in viedDidLoad i have:

subLayer.backgroundColor=[UIColor whiteColor].CGColor;
subLayer.frame=CGRectMake(22, 33, 276, 183);

imageLayer.contents=(id)[UIImage imageNamed:@"A.jpg"].CGImage;
imageLayer.frame=subLayer.bounds;
imageLayer.masksToBounds=YES;
imageLayer.cornerRadius=15.0;

subLayer.shadowColor=[UIColor blackColor].CGColor;
subLayer.cornerRadius=15.0;
subLayer.shadowOpacity=0.8;
subLayer.shadowOffset=CGSizeMake(0, 3);
[subLayer addSublayer:imageLayer];
[self.view.layer addSublayer:subLayer];

It is giving desired output but a bit slow in the simulator. I have not yet tested it in Device. so my question is - Is it OK to move a CALayer containing an image??

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ios