Development path of iOS new features page of weibo

  • 2020-05-10 22:58:13
  • OfStack

BeyondAppDelegate.m


//
// BeyondAppDelegate.m
// 20_ The handsome boy no weibo 
//
// Created by beyond on 14-8-3.
// Copyright (c) 2014 years  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 is executed first 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // 1, Create a window 
  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  // 2, Sets the background color of the window 
  self.window.backgroundColor = [UIColor whiteColor];
  // 3, Call the custom method , To determine whether or not 1 Use this version again app, If it is the first 1 Time to use , The root controller of the window is set to NewFeature The controller , Otherwise,   I'm just going to make the master the root of the window 
  [self versionCodeCheck];
  // 4, Make the window visible 
  [self.window makeKeyAndVisible];
  return YES;
}

//  Custom method , To determine whether or not 1 Use this version again app, If it is the first 1 Time to use , The root controller of the window is set to NewFeature The controller , Otherwise,   I'm just going to make the master the root of the window 
- (void)versionCodeCheck
{
  // 1, User preferences , Take the old version number out of the sandbox 

  NSString *oldVersionCode = [[NSUserDefaults standardUserDefaults] objectForKey:kVersionCodeKey];
  NSString *currentVersionCode = [[[NSBundle mainBundle]infoDictionary] objectForKey:kVersionCodeKey];
 
  //  Compare results based on version number   Go into a different controller 
  //[self stepIntoViewController:currentVersionCode oldVersion:oldVersionCode];
  //return;
  
#warning block test -=============== The following content , And the method it calls , Only used for block Call testing 
  if ([currentVersionCode isEqualToString:oldVersionCode]) {
  //if(0){
    [self enterBeyondVC];
  } else {
    //  The key  , And save the 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 you have Oauth authorization , It goes directly to the main controller , Otherwise,   for Oauth Authorization controller 
  if (1) {
    OauthViewController *oauthVC = [[OauthViewController alloc]init];
    self.window.rootViewController = oauthVC;
    return;
  }
  
  
  //  Enter main controller 
  BeyondViewController *vc =[[BeyondViewController alloc]init];
  self.window.rootViewController = vc;
}

- (void)stepIntoViewController:(NSString *)curVersion oldVersion:(NSString *)oldVersion
{
  //  Compare old and new version Numbers 
  UIViewController *rootViewController = nil;
#warning  Testing new features view
  if ([curVersion isEqualToString:oldVersion]) {
   //  if (0){
    //  It's not the first 1 Time is running , Directly instantiate the master controller , Set the master controller to the root controller of the window 
    //  Enter main controller ( Before the main interface   So let's start with the status bar , restore ) ios 7  invalid 
    // [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    rootViewController = [[BeyondViewController alloc]init];
  } else {
    //  That is the first 1 Time is running , Enter the new feature controller , Set the new feature controller to the root controller of the window , And save the version number 
    //  Enter the new feature controller ( New features before the interface   So let's start with the status bar , hidden ) ios 7  invalid 
    // [UIApplication sharedApplication].statusBarHidden = YES;
    // [[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    rootViewController = [[NewFeatureViewController alloc]init];
    //  The key  , And save the version number 
    [[NSUserDefaults standardUserDefaults]setObject:curVersion forKey:kVersionCodeKey];
  }
  //  Sets the root controller for the window , Is the corresponding controller 
  self.window.rootViewController = rootViewController;
}
@end

NewFeatureViewController.h


//
// NewFeatureViewController.h
// 20_ The handsome boy no weibo 
//
// Created by beyond on 14-8-3.
// Copyright (c) 2014 years  com.beyond. All rights reserved.
//  Use only 1 time , Version of the new feature controller , In the first 1 Enabled the next time you run this version 

#import <UIKit/UIKit.h>

@interface NewFeatureViewController : UIViewController
//  define 1 a block As a member variable , When the start button is clicked , Initialize the main controller , Make it the root controller of the window 
// block with copy
@property (nonatomic,copy) void(^startBlock)(BOOL isShare);
@end

NewFeatureViewController.m


//
// NewFeatureViewController.m
// 20_ The handsome boy no weibo 
//
// Created by beyond on 14-8-3.
// Copyright (c) 2014 years  com.beyond. All rights reserved.
//  Use only 1 time , Version of the new feature controller , In the first 1 Enabled the next time you run this version 
/*
  Writing in the front :
  when 1 Controls are not displayed   when , Check the following 3 A property :
  No width and no height 
 x y  Incorrect coordinates 
  Not added to parent control 
  when 1 When the control cannot be clicked , Check the following properties :
  Their own userinteraction = no
  The father of controls userinteraction = no
  The control itself is beyond the scope of the controller it is in 
 pageController The height cannot be changed , So we can set the height to zero 0, The same goes for other controls 
 
 4, centered   Standard steps : To set up the first center, To set up bounds
 
 5, Toggle button images can be done by toggling the status of the button 
 
 normal : ordinary 
 highlighted  :   Highlight (when people hold the long button) 
 disabled  : failure (controlled by code) 
 selected :  The selected   (controlled by code) 
 
 */
#import "NewFeatureViewController.h"

#define kPicNum 4

#warning viewSize  To change to kWinSize
#define viewSize self.view.bounds.size

@interface NewFeatureViewController ()<UIScrollViewDelegate>
{
  //  Page indicating controller 
  UIPageControl *_pageControl;
  
  //  Because the click event of the open button requires sharing the selected state of the button 
  UIButton *_shareBtn;
}

@end

@implementation NewFeatureViewController

- (BOOL)prefersStatusBarHidden
{
  //  in LoadView before   Also first 
  NSLog(@"prefers bar hidden");
  return YES;
  
}

- (void)loadView
{
  NSLog(@"load view");
  //  New features , let imageView Become a controller view, And then again ImageView Add the above 1 layer scrollView
  UIImageView *imgView = [[UIImageView alloc]init];
  //  Setup controller view( namely imgView) The size of the full screen 
  imgView.frame = [UIScreen mainScreen].bounds;
  NSLog(@"%@",NSStringFromCGRect(imgView.frame));
  //  Use the methods in the taxonomy , If it is iphone5, loading  -568h Pictures of the 
  imgView.image = [UIImage fullScrennImageNamed:@"new_feature_background.png"];
  
  //  Let the controller view You can interact with users 
  imgView.userInteractionEnabled = YES;
  //  Directly to imgeView Become a controller view
  self.view = imgView;
}
- (void)viewDidLoad
{
  [super viewDidLoad];
  NSLog(@"view did load ");

  // 1, Call the custom method , loading UIScrollView, And batch add UIImageView, each ImageView putting 1 image 
  [self addUIScrollView];
  
  // 2, Call the custom method , loading UIPageControl
  [self addUIPageControl];
}

//  Custom method , loading UIScrollView, And batch add UIImageView, each ImageView putting 1 image 
- (void) addUIScrollView
{
  // 1. loading UIScrollView, And batch add UIImageView, each ImageView putting 1 image 
  UIScrollView *scrollView = [[UIScrollView alloc] init];
  //  The size of the visual area displayed 
  scrollView.frame = self.view.bounds;
  //  Horizontal scroll bar 
  scrollView.showsHorizontalScrollIndicator = NO;
  //  Page by visual area 
  scrollView.pagingEnabled = YES;
  //  Rolling range 
  scrollView.contentSize = CGSizeMake(kPicNum * viewSize.width, 0);
  //  The agent   You can listen for various events that scroll 
  scrollView.delegate = self;
  //  Added to the self.view namely ImageView
  [self.view addSubview:scrollView];
  
  // 2, Add by index kPicNum The arrangement of pictures kPicNum a imageView to scrollView inside 
  for (int i = 0; i<kPicNum; i++) {
    [self addImageViewToScrollView:scrollView atIndex:i];
  }

}
//  Custom method , loading UIPageControl
- (void) addUIPageControl
{
  // 1, loading UIPageControl
  _pageControl = [[UIPageControl alloc] init];
  //  Center is best set first center, To set up bounds
  _pageControl.center = CGPointMake(viewSize.width * 0.5, viewSize.height * 0.95);
  _pageControl.bounds = CGRectMake(0, 0, 100, 0);
  //  Set total pages 
  _pageControl.numberOfPages = kPicNum;
  //  Focus on ~ Load the color from the image   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"]];
  //  Disables default interaction events 
  _pageControl.userInteractionEnabled = NO;
  //  Added to the self.view namely ImageView
  [self.view addSubview:_pageControl];
}

// scrollView Proxy method , For dynamic control PageControl Current dot of , Upon completion of the rolling deceleration, the (i.e scrollview Stationary) 
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
  //  The current page is offset x Divided by the width of the sheet 
  _pageControl.currentPage = scrollView.contentOffset.x / scrollView.frame.size.width;
}

//  Custom method , Add by index kPicNum The arrangement of pictures kPicNum a imageView to scrollView inside 
- (void)addImageViewToScrollView:(UIScrollView *)scrollView atIndex:(int)i
{
  // 1. create imageview
  UIImageView *imageView = [[UIImageView alloc] init];
  //  Because it is 1 Spread horizontally , So it's calculated by the index  frame , Through the structure must be strongly converted CGRect
  imageView.frame = (CGRect){{i * viewSize.width, 0} , viewSize};
  
  
  // 2. Set the picture 
  NSString *name = [NSString stringWithFormat:@"new_feature_%d.png", i + 1];

  //  Use the methods in the taxonomy , If it is iphone5, loading  -568h Pictures of the 
  imageView.image = [UIImage fullScrennImageNamed:name];
  
  // 3. add 
  [scrollView addSubview:imageView];
  
  // 4. If it's at the end 1 A picture, add 2 Three buttons (share, start) 
  if (i == kPicNum - 1) {
    //  Must make the last 1 zhang imageView You can click , So it's inside 2 Button can be clicked 
    imageView.userInteractionEnabled = YES;
    
    
    //  The last 1 Picture page , There are two buttons ,1 One is to start 
    [self addStartBtnInImageView:imageView];
    //  The last 1 Picture page , There are two buttons , On the other 1 One is the share tweet button , The default is selected 
    [self addShareBtnInImageView:imageView];
  }
}

//  The last 1 Picture page , There are two buttons ,1 One is to share 
- (void) addShareBtnInImageView:(UIImageView *)imageView
{
  
  // 2.1. Button to create a custom style 
  _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  //  Add to the end 1 zhang imageView inside 
  [imageView addSubview:_shareBtn];
  
  // 2.2. Set the background image of the button 
  //  Call your own classification method , Set the button to normal and highlight the background image , And returns   Size of picture 
  CGSize shareBtnNormalBgImgSize = [_shareBtn setBtnBgImgForNormalAndSelectedWithName:@"new_feature_share_false.png" selectedName:@"new_feature_share_true.png"];
  
  // 2.3. A border ( In the middle , First, center, after bounds)
  _shareBtn.center = CGPointMake(viewSize.width * 0.5, viewSize.height * 0.75);
  //  Button wide high , Just the width and height of the background image 
  _shareBtn.bounds = (CGRect){CGPointZero, shareBtnNormalBgImgSize};
  
  // 2.4. Listening to the 
  [_shareBtn addTarget:self action:@selector(shareBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  // 2.5. Do not change the color of the image when it is highlighted 
  _shareBtn.adjustsImageWhenHighlighted = NO;
  // 2.6. Selected by default 
  _shareBtn.selected = YES;
  
}
//  Share button click events , Just switch the different selected states , You can show two different pictures ( Normal pictures are not checked , The selected image is checked )
- (void)shareBtnClick:(UIButton *)shareBtn
{
  shareBtn.selected = !shareBtn.isSelected;
}
//  The last 1 Picture page , There are two buttons ,1 One is to start 
- (void) addStartBtnInImageView:(UIImageView *)imageView
{
    
  // 1.1. Create open button 
  //  Use custom styles 
  UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  //  Add to the end 1 zhang imageView inside 
  [imageView addSubview:startBtn];
  
  
  // 1.2. Set the background image and other personalized styles 
  //  Call your own classification method , Set the button to normal and highlight the background image , And returns   Size of picture 
  CGSize startBtnBgImgSize = [startBtn setBtnBgImgForNormalAndHighightedWithName:@"new_feature_finish_button.png"];
  // 1.3. A border 
  startBtn.center = CGPointMake(viewSize.width * 0.5, viewSize.height * 0.85);
  //  The width and height of the button   with   The width and height of the background image 1 Large sample 
  startBtn.bounds = (CGRect){CGPointZero, startBtnBgImgSize};
  
  // 1.4. Listening to the 
  [startBtn addTarget:self action:@selector(startBtnClick) forControlEvents:UIControlEventTouchUpInside];
  
}

//  When the start button is clicked , call block complete , The following functions : Initialize the main controller , Make it the root controller of the window 
- (void)startBtnClick
{
  //  Direct call block ( Or the other 1 In class 1 Section of code to execute )
  if (_startBlock) {
    _startBlock(_shareBtn.isSelected);
  }
}

@end


Related articles: