Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在视图中的任何位置检测到水龙头?_Iphone_Ios_Objective C_Xcode - Fatal编程技术网

Iphone 如何在视图中的任何位置检测到水龙头?

Iphone 如何在视图中的任何位置检测到水龙头?,iphone,ios,objective-c,xcode,Iphone,Ios,Objective C,Xcode,我有一个我的应用程序的教程,它应该只在应用程序第一次打开时显示,应该点击关闭 我正在初始化viewDidLoad中的UITapGestureRecognitor: tapper_tut = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; tapper_tut.cancelsTouchesInView = FALSE; [self.view addGestureReco

我有一个我的应用程序的教程,它应该只在应用程序第一次打开时显示,应该点击关闭

我正在初始化viewDidLoad中的UITapGestureRecognitor:

tapper_tut = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
tapper_tut.cancelsTouchesInView = FALSE;
[self.view addGestureRecognizer:tapper_tut];
我有一个iAction来检测点击并将教程设置为隐藏:

- (IBAction)dismiss_tut{
    if (????????????????) {
        _tutorial.hidden = YES;
    }
}
但是我不知道在if语句条件中应该放什么,或者这是否是正确的方法


如何在点击时关闭UIImageView?

您必须将.h文件声明为“UIGestureRecognitizerDelegate”

UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
[self.view addGestureRecognizer:gr];
// if not using ARC, you should [gr release];
// mySensitiveRect coords are in the coordinate system of self.view


- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer {
    CGPoint p = [gestureRecognizer locationInView:self.view];
    if (CGRectContainsPoint(mySensitiveRect, p)) {
        NSLog(@"got a tap in the region i care about");
    } else {
        NSLog(@"got a tap, but not where i need it");
    }
}
你有两个方向的手势点击,如下步骤所示

1) 手势识别器的调用委托方法(未给定操作)

2) 采取行动

 UITapGestureRecognizer *oneTouch=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Addphoto)];
 [oneTouch setNumberOfTouchesRequired:1];
 [self.view addGestureRecognizer:oneTouch];

 -(IBAction)Addphoto
 {
     //whatever you want write code here
 }

可能会有帮助。

您可以这样设置viewDidLoad

- (void)viewDidLoad 
  { 
      [super viewDidLoad];
      self.view.backgroundColor = [UIColor whiteColor];

      /* Create the Tap Gesture Recognizer */
      self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
                                   action:@selector(handleTaps:)]; 

     /* The number of fingers that must be on the screen */
      self.tapGestureRecognizer.numberOfTouchesRequired = 1;

     /* The total number of taps to be performed before the gesture is recognized */
      self.tapGestureRecognizer.numberOfTapsRequired = 1;

     /* Add this gesture recognizer to the view */
     [self.view addGestureRecognizer:self.tapGestureRecognizer];
  }
要检测抽头,可以使用如下方法

- (void) handleTaps:(UITapGestureRecognizer*)paramSender
  {
      NSUInteger touchCounter = 0; 
      for (touchCounter = 0;touchCounter < paramSender.numberOfTouchesRequired;touchCounter++)
      {
            CGPoint touchPoint =[paramSender locationOfTouch:touchCounter inView:paramSender.view];
            NSLog(@"Touch #%lu: %@",(unsigned long)touchCounter+1, NSStringFromCGPoint(touchPoint));
      }
  }
-(void)handleTaps:(UITapGestureRecognitor*)参数发送器
{
整数触摸计数器=0;
对于(touchCounter=0;touchCounter
我认为您需要检测应用程序的第一次启动,您可以使用以下方法执行此操作

!![[NSUserDefaults standardUserDefaults]布尔工作:@“HasLaunchedOnce”]


把这个放在你的if语句中。

你为什么要
if
语句?你读了问题了吗?OP问“我如何在点击时关闭UIImageView?”。我猜他写了一些东西来隐藏教程(_tutorial.hidden=YES),他问的是关于在if语句中放置什么
- (void) handleTaps:(UITapGestureRecognizer*)paramSender
  {
      NSUInteger touchCounter = 0; 
      for (touchCounter = 0;touchCounter < paramSender.numberOfTouchesRequired;touchCounter++)
      {
            CGPoint touchPoint =[paramSender locationOfTouch:touchCounter inView:paramSender.view];
            NSLog(@"Touch #%lu: %@",(unsigned long)touchCounter+1, NSStringFromCGPoint(touchPoint));
      }
  }