2013-04-10 76 views
1

我正在研究一个应用程序,我需要在点击UITapGestureRecognizer时缩放UIView,并且想要在缩放和缩放后执行IBAction。这可能吗?。请给我一个小例子。IBAction无法与UITapGestureRecognizer配合使用

+0

你可以提供你已经有些代码得到? – Tim 2013-04-10 10:06:20

+0

你能给一些代码吗? – DharaParekh 2013-04-10 10:08:20

+0

UITapGestureRecognizer * tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewDoubleTapped :)]; tap2.numberOfTapsRequired = 2; [scrollViewChecking addGestureRecognizer:tap2]; – Varsha 2013-04-10 10:23:00

回答

0

IBAction只是返回void的常规方法,只能使用0或1参数。

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

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

例如下面的代码

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

会称这种方法,当用户doubleTap的ImageView的

- (void) handleTap:(UITapGestureRecognizer *)sender; 
在这种方法

,你几乎可以做任何你需要的东西: 管理你的子视图, 调用其他方法等... 但是,如果你打算放大和缩小,我会强烈建议使用UIScrollVie w类而不是UIView类。

干杯

0

您好,我希望下面会给UA想法.....

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 

} 

上面的代码中并没有进行测试

+0

让我知道你是否面临任何问题 – Spynet 2013-04-10 11:08:14

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; 
    } 
} 
+0

完美的缩放代码,它只会缩放你点击的部分 – 2013-04-10 13:38:13

相关问题