The path of IOS development--The new feature page of Weibo _ios

Source: Internet
Author: User
Tags oauth reserved uikit

BEYONDAPPDELEGATE.M

BEYONDAPPDELEGATE.M//20_ handsome no Weibo////Created by Beyond on 14-8-3. Copyright (c) 2014 Com.beyond.
All rights reserved. #import "BeyondAppDelegate.h" #import "BeyondViewController.h" #import "NewFeatureViewController.h" #import " OauthViewController.h "#define KVERSIONCODEKEY (NSString *) Kcfbundleversionkey @implementation beyondappdelegate// Apply the method that was first executed-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *)
  launchoptions {//1, create window Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];
  2, set the background color of the window Self.window.backgroundColor = [Uicolor Whitecolor];
  3, call the custom method, judge is not the first time using this version of the app, if it is the first time to use, the window's root controller is set to the Newfeature controller, otherwise directly let the main controller into the window of the root controller [self versioncodecheck];
  4, let the window be visible [Self.window makekeyandvisible];
return YES; ///custom method, to determine whether the first use of this version of the app, if it is the first time to use, the window's root controller is set to the Newfeature controller, otherwise the primary controller is directly the root controller of the window-(void) Versioncodecheck {//1, Using user preferences, remove the old version number from the sandbox nsstring *oldversioncode = [[NsuseRdefaults Standarduserdefaults] Objectforkey:kversioncodekey];
 
  NSString *currentversioncode = [[[NSBundle mainbundle]infodictionary] objectforkey:kversioncodekey];
  According to the comparison result of version number, enter different controller//[self Stepintoviewcontroller:currentversioncode Oldversion:oldversioncode];
  
Return #warning block Test-=============== The following, and the method invoked therein, only for block call test if ([Currentversioncode isequaltostring:o
  Ldversioncode]) {//if (0) {[Self ENTERBEYONDVC]; else {//critical, and save version number [[Nsuserdefaults Standarduserdefaults]setobject:currentversioncode Forkey:kversioncodekey]
    
    ;
    Enter the new feature controller Newfeatureviewcontroller *NEWVC = [[Newfeatureviewcontroller alloc]init];
      Newvc.startblock = ^ (BOOL isselected) {log (@ "%d", isselected);
    [Self ENTERBEYONDVC];
    };
  Self.window.rootViewController = NEWVC; } #warning block test-(void) ENTERBEYONDVC {//1, if the OAuth authorization is made, go directly to the primary controller, otherwise the OAuth authorization controller if (1) {Oauthviewco Ntroller *OAUTHVC = [[Oauthviewcontroller Alloc]iniT];
    Self.window.rootViewController = OAUTHVC;
  Return
  }//Enter the main controller Beyondviewcontroller *VC =[[beyondviewcontroller Alloc]init];
Self.window.rootViewController = VC; }-(void) Stepintoviewcontroller: (NSString *) curversion oldversion: (NSString *) oldversion {//Compare new and old version number Uiviewcontroll
Er *rootviewcontroller = nil; #warning to test the new feature of view if ([Curversion isequaltostring:oldversion]) {//if (0) {//description is not the first run, directly instantiate the master controller, set the primary controller as a window Root Controller//Enter the main controller (the main interface before the status bar, restore) iOS 7 invalid//[[UIApplication sharedapplication] Setstatusbarhidden:no withanimation:
    Uistatusbaranimationfade];
  Rootviewcontroller = [[Beyondviewcontroller alloc]init]; else {//description is the first run, enter the new feature controller, set the new feature Controller to the window root controller, and save the version number//Enter the new feature controller (before the new feature interface to the status bar, hide) iOS 7 invalid//[Uiapplicati
    on 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 for the corresponding controller Self.window.rootViewController = Rootviewcontroller;

 } @end

NewFeatureViewController.h


//NewFeatureViewController.h
//20_ handsome no Weibo////
Created by Beyond on 14-8-3.
Copyright (c) 2014 Com.beyond. All rights reserved.
Only once, the version of the new feature controller is enabled

#import <UIKit/UIKit.h> @interface Newfeatureviewcontroller When this version is first run

: Uiviewcontroller
//define a block as a member variable, click the Start button, initialize the host controller to become the window's root controller
//block with copy
@property (nonatomic, copy) void (^startblock) (BOOL isshare);
@end

Newfeatureviewcontroller.m

NEWFEATUREVIEWCONTROLLER.M//20_ handsome no Weibo////Created by Beyond on 14-8-3. Copyright (c) 2014 Com.beyond.
All rights reserved. Use only once, the version of the new feature controller, enable/* write in front of when running this version for the first time: When a control is not displayed, check the following three properties: no width and height x y coordinates are not correctly added to the parent control when a control cannot be clicked, check the following properties: Self userinteraction = no parent control Userinteraction = No control itself has exceeded the height of its controller range Pagecontroller cannot be changed, so you can set the height to 0, the other controls the same as 4, the center-displayed standard  Step: First set center, then set bounds 5, toggle button picture can be changed by the state of the toggle button to complete normal: normal highlighted: Highlighting (artificial long press) Disabled: failure (through code control) selected:  Checked (through code control) * * * * #import "NewFeatureViewController.h" #define Kpicnum 4 #warning viewsize to be converted to Kwinsize #define Viewsize Self.view.bounds.size @interface Newfeatureviewcontroller () <UIScrollViewDelegate> {//page indicator Controller Uipagecontrol
  
  *_pagecontrol;
Because the button to open the click of the event needs to share the button selected state UIButton *_sharebtn;  @end @implementation Newfeatureviewcontroller-(BOOL) Prefersstatusbarhidden {//NSLog before Loadview (@ "prefers
  Bar hidden ");
  
return YES; }-(void) Loadview {NsloG (@ "Load view");
  New features, let ImageView become the controller view, and then ImageView add a layer of scrollview uiimageview *imgview = [[Uiimageview alloc]init];
  Set the size of the controller view (i.e. Imgview) to full screen imgview.frame = [UIScreen mainscreen].bounds;
  NSLog (@ "%@", Nsstringfromcgrect (Imgview.frame));
  
  Using the method in the taxonomy, if it is iphone5, load the -568h picture imgview.image = [UIImage fullscrennimagenamed:@ "New_feature_background.png"];
  Allow the controller's view to interact with the user imgview.userinteractionenabled = YES;
Directly let Imgeview become the controller of view Self.view = Imgview;
  }-(void) viewdidload {[Super viewdidload];

  NSLog (@ "View did load");
  
  1, call the custom method, load the Uiscrollview, and add the Uiimageview in batches, and place a picture in each imageview [self adduiscrollview];
2, call the custom method, load Uipagecontrol [self adduipagecontrol]; ///custom method, load Uiscrollview, and batch add Uiimageview, place one picture in each ImageView-(void) Adduiscrollview {//1. Load Uiscrollview, and batch add Uii
  Mageview, put a picture in each imageview uiscrollview *scrollview = [[Uiscrollview alloc] init];
  The visible area size scrollview.frame = self.view.bounds; Horizontal scroll bar ScrollviEw.showshorizontalscrollindicator = NO;
  Page scrollview.pagingenabled by visual area = YES;
  Rolling range scrollview.contentsize = Cgsizemake (kpicnum * viewsize.width, 0);
  The agent can listen for scrolling various events scrollview.delegate = self;
  
  Add to Self.view that ImageView [Self.view Addsubview:scrollview]; 2, according to the index add Kpicnum picture arranged Kpicnum ImageView into scrollview for (int i = 0; i<kpicnum; i++) {[Self Addimageviewtosc
  Rollview:scrollview ATINDEX:I]; }///custom method, loading Uipagecontrol-(void) Adduipagecontrol {//1, loading Uipagecontrol _pagecontrol = [[Uipagecontrol alloc] I
  NIT];
  Center is best set first, then set bounds _pagecontrol.center = Cgpointmake (viewsize.width * 0.5, viewsize.height * 0.95);
  _pagecontrol.bounds = CGRectMake (0, 0, 100, 0);
  Set total number of pages _pagecontrol.numberofpages = Kpicnum; Focus ~ Load 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"]];
  Prohibit default interaction event _pagecontrol.userinteractionenabled = NO;
Add to Self.view that ImageView [Self.view Addsubview:_pagecontrol]; A//ScrollView proxy method for dynamically controlling the current dot of the Pagecontrol, which is invoked (that is, ScrollView static)-(void) Scrollviewdidenddecelerating: ( Uiscrollview *) ScrollView {//The current first few pages are offset x divided by the single width _pagecontrol.currentpage = scrollview.contentoffset.x/scrollview.f
Rame.size.width; ///Custom method, Kpicnum ImageView to ScrollView-(void) Addimageviewtoscrollview by adding kpicnum picture to the index: (Uiscrollview *)
  ScrollView atindex: (int) I {//1. Create ImageView Uiimageview *imageview = [[Uiimageview alloc] init];
  
  
  Because it is a horizontal arrangement, the frame is computed according to the index, and the structure must be strongly converted to cgrect Imageview.frame = (cgrect) {{i * viewsize.width, 0}, viewsize};

  2. Set picture NSString *name = [NSString stringwithformat:@ "New_feature_%d.png", i + 1];
  
  Using the method in the taxonomy, if it is iphone5, load the -568h picture imageview.image = [UIImage fullscrennimagenamed:name];
 3. Add [ScrollView Addsubview:imageview]; 4. If this is the last picture, add 2 buttons (share, start) if (i = = kPicNum-1) {//must allow the last imageview to be clicked so that the 2 buttons inside it can be clicked Imageview.userint
    
    
    eractionenabled = YES;
    The last picture page has two buttons, one is the beginning [self addstartbtninimageview:imageview];
  Last picture page, there are two buttons, the other is to share the Twitter button, the default is selected state [self addsharebtninimageview:imageview];  //Last Picture page, there are two buttons, one is sharing-(void) Addsharebtninimageview: (Uiimageview *) ImageView {//2.1. Create a custom Style button _sharebtn
  = [UIButton Buttonwithtype:uibuttontypecustom];
  
  Add to the last piece of ImageView [ImageView addsubview:_sharebtn]; 2.2. Set the button background picture//Call Own Write classification method, set the button normal and highlight the background picture, and return the picture size cgsize sharebtnnormalbgimgsize = [_sharebtn Setbtnbgimgforno
  
  rmalandselectedwithname:@ "New_feature_share_false.png" selectedname:@ "New_feature_share_true.png"];
  2.3. Border (center, first center, post bounds) _sharebtn.center = Cgpointmake (viewsize.width * 0.5, viewsize.height * 0.75); The button width is high, the background picture is wide and high _sharebtn.bounds = (cgrect) {Cgpointzero, sharebtnNormalbgimgsize};
  2.4. Listening [_sharebtn addtarget:self action: @selector (Sharebtnclick:) forcontrolevents:uicontroleventtouchupinside];
  2.5. Do not change the picture color _sharebtn.adjustsimagewhenhighlighted = No in the highlight state;
  
2.6. Default check _sharebtn.selected = YES;
  //Share button click events, as long as the switch to different selected states, you can display a different two pictures (normal picture is not checked, the selected state of the picture is checked)-(void) Sharebtnclick: (UIButton *) sharebtn {
sharebtn.selected =!sharebtn.isselected; //Last Picture page, there are two buttons, one is start-(void) Addstartbtninimageview: (Uiimageview *) ImageView {//1.1. Create an Open button//use a custom style U
  IButton *startbtn = [UIButton buttonwithtype:uibuttontypecustom];
  
  
  Add to the last piece of ImageView [ImageView addsubview:startbtn]; 1.2. Set the background picture and other personality style//call their own Write classification method, set the button normal and highlight the background picture, and return the size of the picture cgsize startbtnbgimgsize = [Startbtn setbtnbgimgfornormal
  andhighightedwithname:@ "New_feature_finish_button.png"];
  1.3. Border Startbtn.center = Cgpointmake (viewsize.width * 0.5, viewsize.height * 0.85); The width of the button is the same as the height of the background picture startbtn.bounds = (cgrect) {Cgpointzero, startBtnbgimgsize};
  
1.4. Listening [startbtn addtarget:self action: @selector (Startbtnclick) forcontrolevents:uicontroleventtouchupinside]; //Click on the Start button, call block complete, the following function: Initialize the main controller, let it become the root controller of the window-(void) Startbtnclick {//Direct call block (that is, another class inside a piece of code to execute) if (_startblo
  CK) {_startblock (_sharebtn.isselected);
 }} @end

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.