使用uipinchguesters我正在获得缩放和变换值,如下面的代码
-(void)Scale:(id)sender {
if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
_lastScale = 1.0;
}
CGFloat scale = 1.0 - (_lastScale - [(UIPinchGestureRecognizer*)sender scale]);
CGAffineTransform currentTransform = imgView.transform;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
imgView.layer.allowsEdgeAntialiasing = YES;
[imgView setTransform:newTransform];
// CGAffineTransform newtransform = imgView.transform;
_lastScale = [(UIPinchGestureRecognizer*)sender scale];
[self showOverlayWithFrame:imgView.frame];
CGAffineTransform transform = CGAffineTransformIdentity;
transform=imgView.transform;
NSLog(@"%@",NSStringFromCGAffineTransform(transform));
[[NSUserDefaults standardUserDefaults]
setValue:[NSString stringWithFormat:@"%f",scale] forKey:@"Scale"];
[[NSUserDefaults standardUserDefaults]
setValue:NSStringFromCGAffineTransform(transform) forKey:@"Transform"];
}
然后我在nsuserdefaults中保存变换和缩放值....
并杀死应用程序并再次运行它我们可以映像相同的位置...... 我正在更新像这个比例和转换值
CGRect frameValue = CGRectFromString(
[[NSUserDefaults standardUserDefaults] stringForKey:@"frame"]);
NSString *roatValue=[[NSUserDefaults standardUserDefaults] stringForKey:@"Rotation"];
CGFloat rotation=[roatValue floatValue];
CGAffineTransform currentTransform=CGAffineTransformFromString([[NSUserDefaults standardUserDefaults] stringForKey:@"Transform"]);
NSString *scaleValue=[[NSUserDefaults standardUserDefaults] stringForKey:@"Scale"];
CGFloat scale=[scaleValue floatValue];
Last Session Rotation
imgView.transform=CGAffineTransformScale(currentTransform,scale, scale);
imgView.frame=frameValue;
答案 0 :(得分:2)
通过在UIView上设置frame
- 属性,您将删除图层上的所有转换。
如果视图已转换,请使用bounds
和position
。
尚未测试,但翻转设置顺序可能有效:
imgView.frame = frameValue;
imgView.transform = CGAffineTransformScale(currentTransform, scale, scale);