我正在做一个项目,其中有一系列视频和中间图像供我必须显示的用户交互。起初它工作正常,但是当我第二次执行该应用程序时,它会跳过用户交互。我目前正在处理这段代码:
-(void) playScene
{
if([scenetype isEqualToNumber:[NSNumber numberWithInt: 0]])
{
// plays a video using AVPlayer
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nextScene:)
name:AVPlayerItemDidPlayToEndTimeNotification object:Nil];
}
else
{
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.jpg"]];
imageView.frame = View.bounds;
imageView.userInteractionEnabled = YES;
tapImage = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkTouch:)];
[imageView addGestureRecognizer:tapImage];
[View addSubview:imageView];
}
}
在检查触摸方法;
-(void)checkTouch: (UITapGestureRecognizer *) gesture
{
CGPoint location = [gesture locationInView:imageView];
if(location.x > 20.0 && location.x < 50.0)
{
//somedata
...
[self playScene];
}
else
{
...
[self playScene];
}
}
最后在下一个场景中:
-(void) nextScene: (NSNotification *) anotification
{
if(nextscene)
{
//somedata
...
[self playScene];
}
else
{
exit(0);
}
}
它在 if 条件不成立时显示图像,但它会跳过用户交互方法,进入 nextScene() 方法并在图像上方播放视频。我在这里缺少什么?任何帮助将不胜感激。