2

试图放大/缩小 imageView。

我已经成功地做到了,所以现在我试图在视图上放置一些按钮,并在点击按钮时放大该区域。

我该如何实施?

到目前为止,这是我的代码

-(void)zoomHere:(UIButton *)sender{

    NSLog(@"zoom in");
    //[self performSelector:@selector()
    //         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];
    }


}

并且视图确实加载了

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIView *buttonView = [[UIView alloc]initWithFrame:CGRectMake(00.0, 20.0, 768, 1004.0)];

    zoomHere = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [zoomHere addTarget:self
               action:@selector(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];


}

它仍然会放大,但不会放大按钮所在的屏幕区域!

4

1 回答 1

3

如果你想使用缩放变换,你可能应该
像这样使用平移变换:

CGAffineTransform scale = CGAffineTransformMakeScale(1.05, 1.05);
CGAffineTransform translate = CGAffineTransformMakeTranslation(10, 20);
CGAffineTransform delta = CGAffineTransformConcat(scale, translate);
imageView.transform = CGAffineTransformConcat(imageView.transform, delta);

这就是您知道图像视图上按钮位置的方式:

[imageView convertPoint:button.center fromView:self.view]

因此,如果您知道按钮的坐标和当前的比例,那么您可以计算新的平移变换
但至于我,我宁愿使用滚动视图来放大和缩小该图像视图。你可以有很好的弹跳动画和缩放动画,也可以有平移和捏合,但当然这取决于你。

于 2012-10-16T16:24:16.500 回答