1

我正在开发一个应用程序,我需要UIView在单击时缩放UITapGestureRecognizer并希望IBAction在缩放后执行一段时间的缩放。这可能吗?。请给我一个小例子。

4

3 回答 3

1
- (void)viewDidLoad
{
    [super viewDidLoad];
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDoubleTap:)];
    tapGestureRecognizer.numberOfTapsRequired = 2;
    [self.scrollContainer addGestureRecognizer:tapGestureRecognizer];
}
- (void)handleDoubleTap:(UIGestureRecognizer *)recognizer
{
    if(isAlreadyZoomed)
    {
        CGPoint Pointview = [recognizer locationInView:recognizer.view];
        CGFloat newZoomscal = 3.0;
        CGSize scrollViewSize = self.scrollContainer.bounds.size;
        CGFloat width = scrollViewSize.width/newZoomscal;
        CGFloat height = scrollViewSize.height /newZoomscal;
        CGFloat xPos = Pointview.x-(width/2.0);
        CGFloat yPos = Pointview.y-(height/2.0);
        CGRect rectTozoom = CGRectMake(xPos, yPos, width, height);
        [self.scrollContainer zoomToRect:rectTozoom animated:YES];
        [self.scrollContainer setZoomScale:3.0 animated:YES];
        isAlreadyZoomed = NO;
    }
    else
    {
        [self.scrollContainer setZoomScale:1.0 animated:YES];
        isAlreadyZoomed = YES;
    }
}
于 2013-04-10T13:37:39.383 回答
0

IBAction 只是返回 void 并仅采用 0 或 1 个参数的常规方法。

您可以在代码中调用它们,就像调用任何其他方法之王一样。

UITapGestureRecognizer 旨在在触发时调用 IBAction 方法。您可以从 InterfaceBuilder 或代码中设置它

例如下面的代码

 UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
tap.numberOfTapsRequired = 2;
[imageView addGestureRecognizer:[tap cop]];

当用户双击 imageView 时将调用此方法

- (void) handleTap:(UITapGestureRecognizer *)sender;

在这种方法中,您几乎可以做任何您需要的事情:管理您的子视图,调用其他方法等......但是,如果您计划放大和缩小,我强烈建议使用 UIScrollView 类而不是 UIView 类.

干杯

于 2013-04-10T10:21:33.303 回答
0

嗨,我希望下面能给你一个想法.....

UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewDoubleTapped:)];
 tap2.numberOfTapsRequired = 2;
 [self.view addGestureRecognizer:tap2];


- (void) scrollViewDoubleTapped:(UITapGestureRecognizer *)sender
{
   scrollZoomAdjust.zoomScale=2.0f;// set your required Zoom scale 
   // scrollZoomAdjust is the scroll view that contain the image within it 

}

以上代码未经测试

于 2013-04-10T11:07:26.737 回答