Ios 用户触摸屏幕后如何延迟代码运行

Ios 用户触摸屏幕后如何延迟代码运行,ios,objective-c,Ios,Objective C,我正在做一个点击游戏,点击屏幕开始游戏。 我有这个代码,我需要使这个动画开始后,点击屏幕。现在正在加载游戏时运行(不点击屏幕)。在屏幕上的“用户”选项卡(触摸)后,我需要对其进行哪些更改才能启动此动画?谢谢你的帮助 [super viewDidLoad]; // Set Delay on Animations when Game Start - Animations Area ***** PERFORMS ****** 0.1 [self performSelector:@selector(A

我正在做一个点击游戏,点击屏幕开始游戏。 我有这个代码,我需要使这个动画开始后,点击屏幕。现在正在加载游戏时运行(不点击屏幕)。在屏幕上的“用户”选项卡(触摸)后,我需要对其进行哪些更改才能启动此动画?谢谢你的帮助

[super viewDidLoad];

// Set Delay on Animations when Game Start - Animations Area ***** PERFORMS ****** 0.1
[self performSelector:@selector(Animation) withObject:nil afterDelay:0.1];

将轻触手势识别器添加到视图中,并在选择器中启动动画

-(void) viewDidLoad
{
     [super viewDidLoad];


     UITapGestureRecognizer *tapGestureRg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(beginAnimation)];
    [self.view addGestureRecognizer:tapGestureRg];

}


   -(void) beginAnimation
{
    // Set Delay on Animations when Game Start - Animations Area ***** PERFORMS ****** 0.1
    [self performSelector:@selector(Animation) withObject:nil afterDelay:0.1];
}

如果要在触摸开始时开始动画,请覆盖
-(void)touchesbented:(NSSet*)touchs with event:(UIEvent*)事件
并在那里启动动画。

您可以将点击手势添加到屏幕。如果您有UIViewController,并且希望在UIViewController视图点击时启动动画,则可以按原样使用此代码,也可以更改要点击并启动动画的视图

-(void) viewDidLoad
{
     [super viewDidLoad];

    UITapGestureRecognizer *singleFingerTap = 
      [[UITapGestureRecognizer alloc] initWithTarget:self 
                                              action:@selector(handleSingleTap:)];
    [self.view addGestureRecognizer:singleFingerTap];  //Replace the self.view if you want to add single tap on another view with your view refrence
 }

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {

   [self Animation]; //You should rename this method as animation.Follow naming conventions.
}

或者,他可以只启用触摸并在视图中实现
-touchesbeated:withEvent:
,然后在那里启动动画。诚然,它要求他对视图进行子类化…@NicolasMiari,我在末尾添加了这个选项。