iphone - 双击缩放崩溃并在 iOS 中显示无法识别的扇区

标签 iphone ios ios5

我想实现双击放大和缩小。所以在我的项目中我没有使用任何 xib 或 Storyboard它的纯编程 View (硬编码)。 我的项目中没有 ScrollView ,所以我添加了 ScrollView 并将我的 ImageView 作为 subview 添加到 scoll-view 中。

比我使用“UIGestureRecognizer”和“触摸开始”但是当我按下双击时我的应用程序崩溃了。我不认识问题,因为我是 IOS 的新手请提出一些解决方案

这是我的代码

ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 1024,768)];
UIView *mixContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
mixContainerView.backgroundColor = [UIColor clearColor];
[mixContainerView addSubview:ScrollView];
backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
backgroundImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"app%03d_location%02d_background", location.application.id.intValue, location.id.intValue]];
[ScrollView addSubview:backgroundImageView];

  - (void)tapTwice:(UIGestureRecognizer *)gestureRecognizer{
//on a double tap, call zoomToRect in UIScrollView
float newScale = [ScrollView zoomScale] * 1.5;
if (newScale > self.ScrollView.maximumZoomScale){
    newScale = self.ScrollView.minimumZoomScale;
    CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
    [ScrollView zoomToRect:zoomRect animated:YES];}
else{
    newScale = self.ScrollView.maximumZoomScale;
    CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
    [ScrollView zoomToRect:zoomRect animated:YES];}}
 // Touch began for touch event to display and hide controll buttons
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
 if(((UITouch *)[touches anyObject]).tapCount == 2)
  {
    UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(tapTwice)];
    tapTwice.numberOfTapsRequired = 2;
    //stops tapOnce from overriding tapTwice
    //then need to add the gesture recogniser to a view - this will be the view that recognises the gesture
    [self.view addGestureRecognizer:tapTwice];

  else{
  if(screenTimer)
   {
    [screenTimer invalidate];
    screenTimer = nil;
   }
   mode1View.hidden=NO;
   screenTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(turnOffScreen) userInfo:nil repeats:NO];}}
 - (void)turnOffScreen{
NSLog(@"TURN OFF SCREEN");
if(screenTimer!=nil)
{
mode1View.hidden=YES;
}}
- (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center {

CGRect zoomRect;

// the zoom rect is in the content view's coordinates.
//    At a zoom scale of 1.0, it would be the size of the imageScrollView's bounds.
//    As the zoom scale decreases, so more content is visible, the size of the rect grows.
zoomRect.size.height = [ScrollView frame].size.height / scale;
zoomRect.size.width  = [ScrollView frame].size.width  / scale;

// choose an origin so as to get the right center.
zoomRect.origin.x    = center.x - (zoomRect.size.width  / 2.0);
zoomRect.origin.y    = center.y - (zoomRect.size.height / 2.0);

return zoomRect;

错误

 unrecognized selector sent to instance 0x7b2f540
 2013-03-13 18:46:09.960 VSL[9352:c07] *** Terminating app due to uncaught exception '  NSInvalidArgumentException', reason: '-[ViewController tapTwice]: unrecognized   selector sent to instance 0x7b2f540'
*** First throw call stack:
(0x1f38012 0x1854e7e 0x1fc34bd 0x1f27bbc 0x1f2794e 0x75385a 0x75299b 0x7540df 0x756d2d 0x756cac 0x74ea28 0x4bb972 0x4bbe53 0x499d4a 0x48b698 0x1e93df9 0x1e93ad0 0x1eadbf5 0x1ead962 0x1edebb6 0x1eddf44 0x1edde1b 0x1e927e3 0x1e92668 0x488ffc 0x1fbd 0x1ee5 0x1)
libc++abi.dylib: terminate called throwing an exception

最佳答案

你需要改变:

UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(tapTwice)];

收件人:

 UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(tapTwice:)];

tapTwice: 方法接受一个参数。

关于iphone - 双击缩放崩溃并在 iOS 中显示无法识别的扇区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15392727/

相关文章:

ios - 在 coreplot ios 的同一 Y 轴上绘制负值和正值

iphone - 在 Xcode 4.2 for iOS 项目中安装 Core-Plot

ios5 - 文件不支持ARC功能,如何处理

objective-c - IOS 5 SetNeedsDisplayInRect 导致 FullScreen-Invalidity

iphone - 个人iPhone应用无需付费?

iphone - iPhone编程中如何替换两个不同的字符串

iphone - CCSpeed延时后的Cocos2D调用函数

ios - UIWebView两次启动-iOS

ios - NSURLConnection 在重新启动应用程序后总是失败

iphone - 没有广告时隐藏 iAd 横幅