The User Guide is displayed when iOS development is started for the first time, and the App, UIScrollView, UIPageControl, NSUserDefaults, and uipagecontrol are directly started for the second time.
First, create a controller class for the bootstrap chart.
UserGuideViewController. h and UserGuideViewController. m
#import <UIKit/UIKit.h>#import "firstViewController.h"#define WIDTH self.view.frame.size.width#define HEIGHT self.view.frame.size.height@interface UserGuideViewController : UIViewController<UIScrollViewDelegate>@end
# Import "UserGuideViewController. h "@ interface UserGuideViewController () @ property (strong, nonatomic) UIScrollView * scrollView; @ property (strong, nonatomic) UIPageControl * page; @ property (strong, nonatomic) UIImageView * image1; @ property (strong, nonatomic) UIImageView * image2; @ property (strong, nonatomic) UIImageView * image3; @ property (strong, nonatomic) UIButton * btn; @ end @ implementation UserGuideViewController-(void) viewDidLoad {[super viewDidLoad]; // load the user guide diagram [self initScroll];}-(void) initScroll {self. image1 = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0, WIDTH, HEIGHT)]; self. image1.image = [UIImage imageNamed: @ "1"]; self. image2 = [[UIImageView alloc] initWithFrame: CGRectMake (WIDTH, 0, WIDTH, HEIGHT)]; self. image2.image = [UIImage imageNamed: @ "2"]; self. image3 = [[UIImageView alloc] initWithFrame: CGRectMake (WIDTH * 2, 0, WIDTH, HEIGHT)]; self. image3.image = [UIImage imageNamed: @ "3"]; self. scrollView = [[UIScrollView alloc] initWithFrame: self. view. frame]; self. scrollView. backgroundColor = [UIColor redColor]; self. scrollView. contentSize = CGSizeMake (WIDTH * 3, HEIGHT); // lock the scroll direction self. scrollView. directionalLockEnabled = YES; // sets the page self. scrollView. pagingEnabled = YES; // hide the scroll bar self. scrollView. showsHorizontalScrollIndicator = NO; // set whether to rebound self. scrollView. bounces = NO; // Add button self. btn = [[UIButton alloc] initWithFrame: CGRectMake (80,600,230, 37)]; [self. btn setTitle: @ "try now" forState: 0]; self. btn. titleLabel. font = [UIFont boldSystemFontOfSize: 20]; [self. btn setTitleColor: [UIColor colorWithRed: 1.000 green: 0.886 blue: 0.107 alpha: 1.000] forState: 0]; self. btn. backgroundColor = [UIColor redColor]; [self. btn addTarget: self action: @ selector (firstpressed) forControlEvents: UIControlEventTouchUpInside]; [self. image3 addSubview: self. btn]; // set the attributes of each page. page = [[UIPageControl alloc] init]; CGSize pageSize = CGSizeMake (120, 44); self. page. frame = CGRectMake (WIDTH-pageSize.width) * 0.5, HEIGHT-pageSize.height-40, pageSize. width, pageSize. height); self. page. backgroundColor = [UIColor clearColor]; // set the page number self. page. numberOfPages = 3; self. page. currentPage = 0; self. scrollView. delegate = self; [self. scrollView addSubview: self. image1]; [self. scrollView addSubview: self. image2]; [self. scrollView addSubview: self. image3]; [self. view addSubview: self. scrollView]; [self. view addSubview: self. page]; // open user interaction, otherwise the following button cannot respond to self. image3.userInteractionEnabled = YES;} // The penalty time for the button-(void) firstpressed {// jump to the body [self presentViewController: [firstViewController new] animated: YES completion: ^ {}];}-(void) scrollViewDidScroll :( UIScrollView *) scrollView {// sets the page self. page. currentPage = (int) (scrollView. contentOffset. x/WIDTH);}-(void) didreceivemorywarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} /* # pragma mark-Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation-(void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender {// Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller .} * // @ end
Body page firstViewController. h and firstViewController. m
#import <UIKit/UIKit.h>@interface firstViewController : UIViewController@end
#import "firstViewController.h"@interface firstViewController ()@end@implementation firstViewController- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor redColor];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
AppDelegate. mAppDelegate. h file
#import <UIKit/UIKit.h>#import "firstViewController.h"#import "UserGuideViewController.h"@interface AppDelegate : UIResponder <UIApplicationDelegate>@property(strong,nonatomic)firstViewController *firstVc;@property (strong, nonatomic) UIWindow *window;@end
# Import "AppDelegate. h "@ interface AppDelegate () @ end @ implementation AppDelegate-(BOOL) application :( UIApplication *) application didFinishLaunchingWithOptions :( NSDictionary *) launchOptions {self. firstVc = [[firstViewController alloc] init]; // determines whether the application is started for the first time if (! [[NSUserDefaults standardUserDefaults] boolForKey: @ "firstLaunch"]) {[[NSUserDefaults standardUserDefaults] setBool: YES forKey: @ "firstLaunch"]; NSLog (@ "first start "); // use UserGuideViewController (User Guide page) as the root view UserGuideViewController * userViewController = [[UserGuideViewController alloc] init]; self. window. rootViewController = userViewController;} else {NSLog (@ "not the first start"); // if not the first start, use first as the root view firstViewController * first = [[firstViewController alloc] init]; self. window. rootViewController = first;} self. window. backgroundColor = [UIColor whiteColor]; [self. window makeKeyAndVisible]; return YES;}-(void) applicationWillResignActive :( UIApplication *) application {// Sent when the application is about to move from active to inactive state. this can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. games shocould use this method to pause the game .} -(void) applicationDidEnterBackground :( UIApplication *) application {// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits .} -(void) applicationWillEnterForeground :( UIApplication *) application {// Called as part of the transition from the background to the inactive state; here you can undo records of the changes made on entering the background .} -(void) applicationDidBecomeActive :( UIApplication *) application {// Restart any tasks that were paused (or not yet started) while the application was inactive. if the application was previusly in the background, optionally refresh the user interface .} -(void) applicationWillTerminate :( UIApplication *) application {// Called when the application is about to terminate. save data if appropriate. see also applicationDidEnterBackground :.} @ end
Running Effect
First Run
Second run