不要在 FirstPageViewController.xib 之前手动加载 IntroPageViewController.xib,试试这个:
- 当 FirstPage 加载时,在其顶部显示 IntroPage 视图。
- 延迟或按下跳过按钮后,删除 IntroPage。
就是这样:
使用相应的 xib 文件制作一个 IntroPageViewController。
在 Xcode 中,为该按钮设置一个按钮和一个操作方法。
// in your .h file.
@interface IntroViewController : UIViewController {
UIButton *skipButton;
}
@property (nonatomic, retain) IBOutlet UIButton *skipButton;
-(IBAction)skipPressed;
@end
// in the .m file
-(IBAction)skipPressed {
[self.view removeFromSuperview]; // this removes intro screen from the screen, leaving you FirstView
}
// put this in the viewDidLoad method
- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:@selector(skipPressed) withObject:nil afterDelay:5];
}
// add these in FirstViewController.m
#import "IntroViewController.h"
- (void)viewDidLoad {
[super viewDidLoad];
IntroViewController *introViewController = [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:[NSBundle mainBundle]];
[self.view addSubview:introViewController.view];
[introViewController release]; // this removes your IntroScreen from memory once it disappears offscreen
}
现在下一步是在 Interface Builder 中打开 IntroViewController.xib 并将 UIButton 拖到视图中,将其标题设置为“Skip”。
将按钮连接到skipPressed操作并将 File's Owner 连接到按钮。
回到 Xcode 并Build and Run来测试它。如果一切正常,您的 IntroView 应该在启动时可见 5 秒,或者直到您触摸“跳过”按钮。