我有一個CALayer,並且作爲這個CALayer的子圖層,我添加了一個imageLayer,其中包含分辨率爲276x183的圖像。使用UIPanGestureRecognizer在視圖周圍移動子圖層是不錯的選擇嗎?
我添加了一個UIPanGestureRecognizer到主視圖和計算的CALayer的座標如下:
- (void)panned:(UIPanGestureRecognizer *)sender{
subLayer.frame=CGRectMake([sender locationInView:self.view].x-138, [sender locationInView:self.view].y-92, 276, 183);
}
在viedDidLoad我有:
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];
這是給需要的輸出,但有點慢在模擬器中。我還沒有在Device中測試過它。所以我的問題是 - 移動包含圖像的CALayer可以嗎?