// // // 20_Handsome guy no Weibo// // Created by beyond on 14-8-3. // Copyright (c) 2014. All rights reserved.// #import "" #import "" #import "" #import "" #define kVersionCodeKey (NSString *)kCFBundleVersionKey @implementation BeyondAppDelegate // The first method to execute- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 1, create a window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // 2, set the background color of the window = [UIColor whiteColor]; // 3. Call a custom method to determine whether it is the first time you use this version of the app. If it is the first time you use it, set the root controller of the window as the NewFeature controller, otherwise the main controller will be the root controller of the window. [self versionCodeCheck]; // 4, make the window visible [ makeKeyAndVisible]; return YES; } // Custom method to determine whether it is the first time to use this version of the app. If it is the first time to use it, set the root controller of the window as the NewFeature controller, otherwise the main controller will be the root controller of the window directly- (void)versionCodeCheck { // 1. Use user preferences to remove the old version number from the sandbox NSString *oldVersionCode = [[NSUserDefaults standardUserDefaults] objectForKey:kVersionCodeKey]; NSString *currentVersionCode = [[[NSBundle mainBundle]infoDictionary] objectForKey:kVersionCodeKey]; // Enter different controllers according to the comparison results of the version number //[self stepIntoViewController:currentVersionCode oldVersion:oldVersionCode]; //return; #warning block test -=================== The following content and the methods called in it are only used for block call testing if ([currentVersionCode isEqualToString:oldVersionCode]) { //if(0){ [self enterBeyondVC]; } else { // Key, and save the version number [[NSUserDefaults standardUserDefaults]setObject:currentVersionCode forKey:kVersionCodeKey]; // Enter the new feature controller NewFeatureViewController *newVC = [[NewFeatureViewController alloc]init]; = ^(BOOL isSelected){ log(@"%d",isSelected); [self enterBeyondVC]; }; = newVC; } } #warning block test - (void) enterBeyondVC { // 1. If Oauth authorization has been performed, it will go directly to the main controller, otherwise Oauth authorization has been performed. if (1) { OauthViewController *oauthVC = [[OauthViewController alloc]init]; = oauthVC; return; } // Enter the main controller BeyondViewController *vc =[[BeyondViewController alloc]init]; = vc; } - (void)stepIntoViewController:(NSString *)curVersion oldVersion:(NSString *)oldVersion { // Compare the new and old version numbers UIViewController *rootViewController = nil; #warning Test new features view if ([curVersion isEqualToString:oldVersion]) { // if (0){ // It means that it is not the first time to run. Directly instantiate the main controller and set the main controller as the root controller of the window. // Enter the main controller (before the main interface, please restore the status bar first) ios 7 is invalid // [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade]; rootViewController = [[BeyondViewController alloc]init]; } else { // Instructions are the first time to run, enter the new feature controller, set the new feature controller as the root controller of the window, and save the version number // Enter the new feature controller (before the new feature interface, hide the status bar first) ios 7 is invalid // [UIApplication sharedApplication].statusBarHidden = YES; // [[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]; rootViewController = [[NewFeatureViewController alloc]init]; // Key, and save the version number [[NSUserDefaults standardUserDefaults]setObject:curVersion forKey:kVersionCodeKey]; } // Set the root controller of the window to be the corresponding controller = rootViewController; } @end
// // // 20_Handsome guy no Weibo// // Created by beyond on 14-8-3. // Copyright (c) 2014. All rights reserved.// Only use once, the new feature controller of the version is enabled when the first time this version is run #import <UIKit/> @interface NewFeatureViewController : UIViewController // Define a block as a member variable. When clicking the Start button, initialize the main controller and make it the root controller of the window// Block with copy@property (nonatomic,copy) void(^startBlock)(BOOL isShare); @end
// // // 20_Handsome guy no Weibo// // Created by beyond on 14-8-3. // Copyright (c) 2014. All rights reserved.// Only use once, the new feature controller of the version is enabled when the first time this version is run/* Written before: When a control is not displayed, check the following three properties: No width and height x y coordinates are incorrect Not added to parent control When a control cannot be clicked, check the following properties: Your own userinteraction = no The userinteraction of the parent control = no The control itself is already beyond the scope of the controller it is located in The height of the pageController cannot be changed, so the height can be set to 0, the same applies to other controls. 4. Standard steps for center display: first set the center, then set the bounds 5. The switch button picture can be completed by switching the state of the button. Normal: Normal highlighted: Highlighted (when artificially long pressed) disabled: failed (by code control) selected: Selected (controlled by code) */ #import "" #define kPicNum 4 #warning viewSize to change to kWinSize#define viewSize @interface NewFeatureViewController ()<UIScrollViewDelegate> { // Page indicator controller UIPageControl *_pageControl; // Because the button selection status needs to be shared in the click event of the button UIButton *_shareBtn; } @end @implementation NewFeatureViewController - (BOOL)prefersStatusBarHidden { // Before LoadView NSLog(@"prefers bar hidden"); return YES; } - (void)loadView { NSLog(@"load view"); // New feature, let imageView become the controller's view, and then add a layer of scrollView on the ImageView UIImageView *imgView = [[UIImageView alloc]init]; // Set the size of the controller view (i.e. imgView) to full screen = [UIScreen mainScreen].bounds; NSLog(@"%@",NSStringFromCGRect()); // Use the method in the classification. If it is iPhone5, load the image with -568h = [UIImage fullScrennImageNamed:@"new_feature_background.png"]; // Let the controller's view interact with the user = YES; // Make imgeView the controller's view directly = imgView; } - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"view did load "); // 1. Call custom methods, load UIScrollView, and add UIImageView in batches, put an image in each ImageView [self addUIScrollView]; // 2, call custom method, load UIPageControl [self addUIPageControl]; } // Customize the method, load the UIScrollView, and add the UIImageView in batches, put an image in each ImageView- (void) addUIScrollView { // 1. Load the UIScrollView and add the UIImageView in batches, put an image in each ImageView UIScrollView *scrollView = [[UIScrollView alloc] init]; // The visible area size displayed = ; // Horizontal scroll bar = NO; // Paginate by visual area = YES; // Scroll range = CGSizeMake(kPicNum * , 0); // Agent can listen to various scrolling events = self; // Add to ImageView [ addSubview:scrollView]; // 2. Add kPicNum imageViews arranged by kPicNum images according to the index to scrollView for (int i = 0; i<kPicNum; i++) { [self addImageViewToScrollView:scrollView atIndex:i]; } } // Custom method, load UIPageControl- (void) addUIPageControl { // 1, load UIPageControl _pageControl = [[UIPageControl alloc] init]; // It is best to set the center first and then set the bounds _pageControl.center = CGPointMake( * 0.5, * 0.95); _pageControl.bounds = CGRectMake(0, 0, 100, 0); // Set the total number of pages _pageControl.numberOfPages = kPicNum; // Focus ~ Loading color from picture Default color and current page color _pageControl.pageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"new_feature_pagecontrol_point.png"]]; _pageControl.currentPageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"new_feature_pagecontrol_checked_point.png"]]; // Disable default interaction events _pageControl.userInteractionEnabled = NO; // Add to ImageView [ addSubview:_pageControl]; } // The proxy method of scrollView is used to dynamically control the current dot of PageControl. It will be called after scrolling and deceleration is completed (that is, scrollview is still)- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { // The current page is the offset x divided by the single width _pageControl.currentPage = / ; } // Custom method, add kPicNum imageViews arranged by kPicNum images according to the index to scrollView- (void)addImageViewToScrollView:(UIScrollView *)scrollView atIndex:(int)i { // 1. Create imageview UIImageView *imageView = [[UIImageView alloc] init]; // Because it is arranged horizontally, the frame must be calculated according to the index, and the structure must be strongly converted to CGRect according to the index. = (CGRect){{i * , 0} , viewSize}; // 2. Set pictures NSString *name = [NSString stringWithFormat:@"new_feature_%", i + 1]; // Use the method in the classification. If it is iPhone5, load the image with -568h = [UIImage fullScrennImageNamed:name]; // 3. Add [scrollView addSubview:imageView]; // 4. If it is the last picture, add 2 buttons (share, start) if (i == kPicNum - 1) { // The last imageView must be clicked so that the two buttons in it can be clicked = YES; // The last picture page has two buttons, one is the beginning [self addStartBtnInImageView:imageView]; // There are two buttons on the last picture page, the other is the share Weibo button, which is selected by default [self addShareBtnInImageView:imageView]; } } // The last picture page has two buttons, one is sharing- (void) addShareBtnInImageView:(UIImageView *)imageView { // 2.1. Create custom style buttons _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // Add to the last imageView [imageView addSubview:_shareBtn]; // 2.2. Set button background picture // Call the classification method you wrote yourself to set the background image of the normal and highlighted buttons, and return the image size CGSize shareBtnNormalBgImgSize = [_shareBtn setBtnBgImgForNormalAndSelectedWithName:@"new_feature_share_false.png" selectedName:@"new_feature_share_true.png"]; // 2.3.Border (center first, center first, bounds later) _shareBtn.center = CGPointMake( * 0.5, * 0.75); // The button width and height are pressed on the background image _shareBtn.bounds = (CGRect){CGPointZero, shareBtnNormalBgImgSize}; // 2.4. Monitoring [_shareBtn addTarget:self action:@selector(shareBtnClick:) forControlEvents:UIControlEventTouchUpInside]; // 2.5. Do not change the color of the picture when highlighted _shareBtn.adjustsImageWhenHighlighted = NO; // 2.6. Selected by default _shareBtn.selected = YES; } // Share button click event, as long as you switch to different selected states, two different pictures can be displayed (normal pictures are not checked, and the pictures in the selected state are checked)- (void)shareBtnClick:(UIButton *)shareBtn { = !; } // The last picture page has two buttons, one is the beginning- (void) addStartBtnInImageView:(UIImageView *)imageView { // 1.1. Create the Open button // Use custom styles UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // Add to the last imageView [imageView addSubview:startBtn]; // 1.2. Set personalized styles such as background pictures // Call the classification method you wrote yourself to set the background image of the normal and highlighted buttons, and return the image size CGSize startBtnBgImgSize = [startBtn setBtnBgImgForNormalAndHighightedWithName:@"new_feature_finish_button.png"]; // 1.3.Border = CGPointMake( * 0.5, * 0.85); // The width and height of the button are as big as the width and height of the background image = (CGRect){CGPointZero, startBtnBgImgSize}; // 1.4. Monitoring [startBtn addTarget:self action:@selector(startBtnClick) forControlEvents:UIControlEventTouchUpInside]; } // When clicking the Start button, the call to block is completed. The following functions: Initialize the main controller and make it the root controller of the window- (void)startBtnClick { // Directly call block (that is, a piece of code in another class to execute) if (_startBlock) { _startBlock(_shareBtn.isSelected); } } @end