IOS 10th lesson, navigation bar dynamic Change effect

Source: Internet
Author: User
Tags reserved

0: First, or through the pure code to achieve

0: Delete 3 files Viewcontroller.h,viewcontroller.m,main.storyboard

1: Modify click on the blue button on the left, then select general-"Developer info-" main interface, will this main interface clear sky

2: Then create a mainuiviewcontroller, it inherits from Uiviewcontroller

1: Update the APPDELEGATE.M file

APPDELEGATE.M//Tennavigationviewtableview/////Created by thousand Ya Dad on 16/10/16. COPYRIGHT©2016 year Kodulf.
All rights reserved.

#import "AppDelegate.h" #import "MainViewController.h" @interface appdelegate () @end @implementation appdelegate -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {//Ove
    Rride point for customization after application launch.
    Self.window = [[UIWindow alloc]initwithframe:[uiscreen mainscreen].bounds];
    Mainviewcontroller *mainviewcontroller=[[mainviewcontroller Alloc]init]; If you do not fill out here is Uinavigationcontroller then the navigation bar is not displayed//notice here must be filled out is Uinavigationcontroller uinavigationcontroller *uinavigat
    Ioncontroller = [[Uinavigationcontroller Alloc]initwithrootviewcontroller:mainviewcontroller];
    [Self.window Setrootviewcontroller:uinavigationcontroller];
    [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 a incoming phone call or SMS message) or the US
    Er quits the application and it begins the transition to the background state. Use the To pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates.
Games should to pause the game. }-(void) Applicationdidenterbackground: (uiapplication *) Application { , save user data, invalidate timers, and store enough application state information to restore your application to its cur
    Rent state in case it is terminated later. If your application supports background execution, this 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 many of the changes made on entering the background.  }-(void) Applicationdidbecomeactive: (uiapplication *) application {//Restart any tasks this were paused (or not yet started) while the application is inactive.
If the application is previously in the background, optionally refresh the user interface. }-(void) Applicationwillterminate: (uiapplication *) application {//called when the application was about to Terminat E. Save data if appropriate.
Also applicationdidenterbackground:.
 } @end


MAINVIEWCONTROLLER.M//Tennavigationviewtableview/////Created by thousand Ya Dad on 16/10/16. COPYRIGHT©2016 year Kodulf.
All rights reserved. #import "MainViewController.h"//todo remember, here must be set to implement the Protocol, or Scrollviewdidscroll will not be able to find @interface Mainviewcontroller ( ) <UITableViewDelegate,UITableViewDataSource> @property (nonatomic,strong) UITableView *tableview;//

TableView is actually Android's ListView @property (Nonatomic,strong) Uinavigationbar *navigationbar;
    @end @implementation Mainviewcontroller-(void) viewdidload {[Super viewdidload];
    [Self.view Setbackgroundcolor:[uicolor Greencolor]];
    Hide the system from the navigation bar, because we want to achieve the effect of the gradient, navigation bars are customized [Self.navigationcontroller Setnavigationbarhidden:yes];
    Let the navigation bar not affect the TableView view, so add the starting coordinates, [self setautomaticallyadjustsscrollviewinsets:no];
    This added tableview will not do automatic stop hungry adjusted [self intiwithnavigationbar];
    [Self inittableview];
Do no additional setup after loading the view. }-(void) inittableview{[self settablEview:[[uitableview alloc]initwithframe:cgrectmake (0, 0, cgrectgetwidth (self.view.bounds), Cgrectgetheight ( self.view.bounds)) Style:uitableviewstyleplain]];//cgrectgetwidth (self.view.bounds), Cgrectgetheight (
    Self.view.bounds) Gets the length of the space, a bit like Android's way of acquiring space length [Self.tableview setdatasource:self];
    [Self.tableview setdelegate:self];
    [Self.tableview Setseparatorstyle:uitableviewcellseparatorstylenone]; [Self.tableview Setcontentinset:uiedgeinsetsmake (64, 0, 0, 0)];//a bit like Android inside the padding sits down right; [Self.tableview Registerc
    Lass:[uitableviewcell class] forcellreuseidentifier:@ "Cell"];

[Self.view AddSubview:self.tableView]; }-(void) intiwithnavigationbar{[self Setnavigationbar:[[uinavigationbar alloc]initwithframe:cgrectmake (0, 0, CGRect
    GetWidth (Self.view.bounds), 64)]]; [Self.navigationbar setbackgroundcolor:[uicolor yellowcolor]];////Remove opacity effect [Self.navigationbar SetTranslucent:N
    O]; [Self.navigationController.view addSubview:self.navigationBar]; If the background layer is not removed, there will be a problem for (UIView *subview in self.navigationBar.subviews) {if ([Subview Iskindofclass:[nsclassfro
        Mstring (@ "_uinavigationbarbackground") class]] {[Subview removefromsuperview];
    }}-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated.
    #pragma mark-table View delegate-///This corresponds to the method after implementing the interface in Java-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{
    Uicolor *color = Self.navigationBar.backgroundColor;
        CGFloat OffsetY = scrollview.contentoffset.y;//upward for positive if (offsety>0) {cgfloat alpha = (600-offsety)/600;
    Self.navigationBar.backgroundColor =[color Colorwithalphacomponent:alpha];
    }else{self.navigationBar.backgroundColor =[color colorwithalphacomponent:1]; } #pragma mark-table View data Source--(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteg ER) section{return 100;}
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (nonnull nsindexpath *) indexPath{UITab Leviewcell *cell = [TableView dequeuereusablecellwithidentifier:@ "Cell"];//will be fetched from the reuse queue [Cell.textlabel setText:[
    NSString stringwithformat:@ "Row-%zd", Indexpath.row]; [Cell Setbackgroundcolor:[[uicolor Graycolor] colorwithalphacomponent:1.0/(Arc4random ()%5)]];//method of generating random numbers,
Arc4random (), and Java slightly different return cell; }/* #pragma mark-navigation//In a storyboard-based application, you'll often want to do a little preparation Re Navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller US
    ing [Segue Destinationviewcontroller].
Pass the selected object to the new view controller.
 } * * @end

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.