iOS如何在显示default.png时点击屏幕继续

时间:2012-12-01 03:19:41

标签: ios tap

就像一些iOS游戏一样,当你点击屏幕时,它会转到主窗口。有人可以告诉我如何在我的应用程序中使用它吗?非常感谢!

2 个答案:

答案 0 :(得分:1)

在视图中,首先在头文件方法中执行以下操作:

@property (nonatomic, strong) UIImageView *myImageView;

在实现文件(.m文件)中,在viewDidLoadMethod中执行以下操作:

self.myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"default.png"]];
self.myImageView.frame = CGRectMake(0, 0, self.myImageView.frame.size.width, self.myImageView.frame.size.height);
self.myImageView.userInteractionEnabled = YES;

UITapGestureRecognizer *imageTapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(defaultImageTapped)];
[self.myImageView addGestureRecognizer:imageTapped];
[self.view addSubview:self.myImageView];

然后在同一个文件中编写此方法并根据您是否想要淡入淡出来选择内部代码:

- (void) defaultImageTapped {
    [self.myImageView removeFromSuperview];

    //Or if you want a nice fading animation
    [UIView animateWithDuration:1.0f animations:^{
        self.myImageView.alpha = 0;
    } completion:^(BOOL finished) {
        [self.myImageView removeFromSuperview];
    }];
}

希望有所帮助。

答案 1 :(得分:0)

首先,添加一个ViewController以显示需要点击的屏幕。然后,使用

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

在第一个ViewController中加载下一个ViewController。