我正在研究一个应用程序,我需要在点击UITapGestureRecognizer
时缩放UIView
,并且想要在缩放和缩放后执行IBAction
。这可能吗?。请给我一个小例子。IBAction无法与UITapGestureRecognizer配合使用
1
A
回答
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
相关问题
- 1. Ctrl-C无法与PyQt配合使用
- 2. OnItemClickListener无法与LocationManager配合使用
- 3. Annotation_raster无法与scale_x_reverse配合使用
- 4. Capistrano/rails无法与rvm配合使用
- 5. sIFR无法与Adobe CS4配合使用
- 6. PHP无法与SQLite配合使用
- 7. Google Adsense无法与Drupal配合使用
- 8. 无法使用Resharper 6.0与xUnit.net配合使用
- 9. 无法在IIS7.5上使用ELMAH与ASP.NET MVC2配合使用
- 10. UITapGestureRecognizer无法添加到UIView?
- 11. 使用UITapGestureRecognizer
- 12. 无法将HTTPS与ServerXMLHTTP对象配合使用
- 13. 无法通过heroku与Rackspace配合使用carrierwave
- 14. PHP 5.5,无法获得call_user_func_array与bing_param配合使用
- 15. Ionic cordova插件编译窗口无法与CLI配合使用
- 16. mini_magick gem无法与我的ImageMagick安装配合使用
- 17. wkhtmltoimage无法与CentOs上的websnap/imgkit配合使用
- 18. 在网格上,CheckboxModel无法与分组配合使用
- 19. 无法让Google Analytics插件与PhoneGap 2.0配合使用
- 20. 为什么NSUserDefaults无法与Firebase配合使用
- 21. 无法让我的菜单与“StickyPanel”配合使用
- 22. 更改日历视图后,Qtip无法与fullcalendar配合使用
- 23. 启动进程无法与VSIXInstaller.exe配合使用
- 24. OpenID在升级到ver4后无法与DotNetOpenAuth配合使用
- 25. npm无法与节点v0.4.12配合使用mac
- 26. FindControl无法与我的ChangePassword控件配合使用
- 27. SyncFolderHierarchy无法与Exchange Server 2007配合使用
- 28. 无法获取Ajax与键控api配合使用
- 29. Prism V2无法与Silverlight 3.0配合使用
- 30. PySpark中的ParamGridBuilder无法与LinearRegressionSGD配合使用
你可以提供你已经有些代码得到? – Tim 2013-04-10 10:06:20
你能给一些代码吗? – DharaParekh 2013-04-10 10:08:20
UITapGestureRecognizer * tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewDoubleTapped :)]; tap2.numberOfTapsRequired = 2; [scrollViewChecking addGestureRecognizer:tap2]; – Varsha 2013-04-10 10:23:00