gpt4 book ai didi

objective-c - 触摸 ImageView 到另一个 ViewController

转载 作者:行者123 更新时间:2023-11-28 22:48:43 25 4
gpt4 key购买 nike

我有 2 个 ViewControllers,我创建了一个 UIImageView 来像 iPhone 上的启动画面一样显示。我把它写在 TestAppDelegate.m 中:

====================

splashScreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

splashScreen.image = [UIImage imageNamed:@"Default.png"];

[self.window addSubview:splashScreen];

sleep(6);

[splashScreen removeFromSuperview];

====================

我的问题是,

如果我触及这个 imageview,我将转到第二个 ViewController

else time sleep 后,自动转到第一个 ViewController

那么,有可能做到吗?

最佳答案

这样做:

在 appDelegate.h 文件中添加 UIGestureRecognizerDelegate。

@interface AppDelegate : UIResponder <UIApplicationDelegate,UIGestureRecognizerDelegate>

现在

splashScreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashScreen.userInteractionEnabled = YES;
splashScreen.image = [UIImage imageNamed:@"Default.png"];
UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 1;
tapRecognizer.delegate = self;
[splashScreen addGestureRecognizer:tapRecognizer];
[tapRecognizer release];

[self.window addSubview:splashScreen];

sleep(6);
[splashScreen removeFromSuperview];
//add ViewController1 here
ViewController1 *objViewController1 = [[ViewController1 alloc]initWithNibName:@"ViewController1" bundle:nil];
[self.window addSubview:objViewController1.view];

现在在启动画面上点击时将调用处理程序

- (void)handleTap:(UITapGestureRecognizer*)recognizer
{
// Do Your thing.
if (recognizer.state == UIGestureRecognizerStateEnded)
{
[splashScreen removeFromSuperview]; //edited here
ViewController2 *objViewController2 = [[ViewController2 alloc]initWithNibName:@"ViewController2" bundle:nil];
[self.window addSubview:objViewController2.view];
}
}

关于objective-c - 触摸 ImageView 到另一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12524160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com