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

标签 objective-c ios uiviewcontroller uiimageview

我有 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/

相关文章:

ios - 如何检测弹出窗口关闭

iphone - 忽略对背景( super ) View 的触摸

iphone - 两个 View Controller 之间viewDidAppear和viewDidDisappear的回调顺序

ios - Facebook News 纸质应用,全尺寸图像视差效果

iphone - iPhone 编程中属性的使用

objective-c - 如何抑制自动保存 “The file has been changed by another application” 警报?

objective-c - 隐藏 UIImagePickerControllerSourceTypceCamera 工具栏,但特定按钮?

iphone - 为什么 UIViewController 在屏幕上被释放

objective-c - iOS 上的自定义 EQ AudioUnit

iphone - 方向改变时重新定位控件