尝试放大/缩小 imageView。
我已经成功地做到了,所以现在我尝试在 View 上放置一些按钮,并在点击按钮时放大该区域。
我该如何实现?
这是我目前的代码
-(void)zoomHereUIButton *)sender{
NSLog(@"zoom in");
//[self performSelectorselector()
// withObject:nil
// afterDelay:1.6f];
CGAffineTransform transformer = CGAffineTransformScale(imageView.transform, 1.05, 1.05);
if (transformer.a < 5) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.2];
imageView.transform = transformer;
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
}
View 确实加载了
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *buttonView = [[UIView alloc]initWithFrame:CGRectMake(00.0, 20.0, 768, 1004.0)];
zoomHere = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[zoomHere addTarget:self
actionselector(zoomHere
forControlEvents:UIControlEventTouchDown];
[zoomHere setTitle"ZoomIN" forState:UIControlStateNormal];
zoomHere.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[buttonView addSubview:zoomHere];
buttonView.multipleTouchEnabled = YES;
[self.view addSubview:buttonView];
}
它仍会放大,但不会放大按钮所在的屏幕区域!
如果你想使用缩放变换,你可能也应该使用平移变换
像这样:
CGAffineTransform scale = CGAffineTransformMakeScale(1.05, 1.05);
CGAffineTransform translate = CGAffineTransformMakeTranslation(10, 20);
CGAffineTransform delta = CGAffineTransformConcat(scale, translate);
imageView.transform = CGAffineTransformConcat(imageView.transform, delta);
这是你如何知道按钮在你的 ImageView 上的位置:
[imageView convertPoint:button.center fromView:self.view]
因此,如果您知道按钮的坐标和当前比例,那么您可以计算新的平移变换
但至于我,我宁愿使用 ScrollView 来放大和缩小该 ImageView 。你可以有很好的弹跳动画和缩放动画,也可以有平移和捏合,当然这取决于你。
关于ios - 放大 UIImageView 和 UIImageView.center,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12918945/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |