IOS development-show user guide when an application is started for the first time

Source: Internet
Author: User

The focus of this function is to determine how the application is started for the first time. It is actually very simple.

We only need to write the user guide page in a class, which is basically implemented using UIScrollView,

Create a class inherited from UIViewController named UserGuideViewController,

Write in UserGuideViewController. m


1-(void) viewDidLoad
2 {
3 [super viewDidLoad];
4 // Do any additional setup after loading the view.
5 self. view. backgroundColor = [UIColor redColor];
6
7 [self initGuide]; // load the New User Guide page
8}
9
10-(void) initGuide
11 {
12 UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake (0, 0,320,640)];
13 [scrollView setContentSize: CGSizeMake (1280, 0)];
14 [scrollView setPagingEnabled: YES]; // View display on the entire page
15 // [scrollView setBounces: NO]; // avoid the bounce effect and expose the Root View
16
17 UIImageView * imageview = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0,320,460)];
18 [imageview setImage: [UIImage imageNamed: @ "0.png"];
19 [scrollView addSubview: imageview];
20 [imageview release];
21
22 UIImageView * imageview1 = [[UIImageView alloc] initWithFrame: CGRectMake (320, 0,320,460)];
23 [imageview1 setImage: [UIImage imageNamed: @ "1.png"];
24 [scrollView addSubview: imageview1];
25 [imageview1 release];
26
27 UIImageView * imageview2 = [[UIImageView alloc] initWithFrame: CGRectMake (640, 0,320,460)];
28 [imageview2 setImage: [UIImage imageNamed: @ "2.png"];
29 [scrollView addSubview: imageview2];
30 [imageview2 release];
31
32 UIImageView * imageview3 = [[UIImageView alloc] initWithFrame: CGRectMake (960, 0,320,460)];
33 [imageview3 setImage: [UIImage imageNamed: @ "3.png"];
34 imageview3.userInteractionEnabled = YES; // enable user interaction in imageview3; otherwise, the following button cannot respond.
35 [scrollView addSubview: imageview3];
36 [imageview3 release];
37
38 UIButton * button = [UIButton buttonWithType: UIButtonTypeCustom]; // load a transparent button on imageview3
39 [button setTitle: nil forState: UIControlStateNormal];
40 [button setFrame: CGRectMake (46,371,230, 37)];
41 [button addTarget: self action: @ selector (firstpressed) forControlEvents: UIControlEventTouchUpInside];
42 [imageview3 addSubview: button];
43
44 [self. view addSubview: scrollView];
45 [scrollView release];
46}
Button Method

1-(void) firstpressed
2 {
3 [self presentModalViewController: [[[WeiBoViewController alloc] init] autorelease] animated: YES]; // click the button to jump to the Root View
4}
 

As for adding a button, it is because my user guides the last page to have a painted button, which indicates that it is used to add a transparent button on it to call the method.

 

Open AppDelegate. m

First introduce the header file


1 # import "UserGuideViewController. h"
2 # import "WeiBoViewController. h"
WeiBoViewController is my root view application: didfinishlaunchingwitexceptions: Judgment in Method


1-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
2 {
3 self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen] bounds] autorelease];
4 // Override point for customization after application launch.
5
6 // determine if the application is started for the first time
7 if (! [[NSUserDefaults standardUserDefaults] boolForKey: @ "firstLaunch"])
8 {
9 [[NSUserDefaults standardUserDefaults] setBool: YES forKey: @ "firstLaunch"];
10 NSLog (@ "first startup ");
11 // use UserGuideViewController (User Guide page) as the root view if it is started for the first time
12 UserGuideViewController * userGuideViewController = [[UserGuideViewController alloc] init];
13 self. window. rootViewController = userGuideViewController;
14 [userGuideViewController release];
15}
16 else
17 {
18 NSLog (@ "not started for the first time ");
19 // use LoginViewController as the root view if it is not started for the first time
20 WeiBoViewController * weiBoViewController = [[WeiBoViewController alloc] init];
21 self. window. rootViewController = weiBoViewController;
22 [weiBoViewController release];
23
24}
25
26 self. window. backgroundColor = [UIColor whiteColor];
27 [self. window makeKeyAndVisible];
28 return YES;
29}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.