Summary
This chapter mainly uses Presentviewcontroller and dismissviewcontrolleranimated to implement the custom multi-view switch, the example inside simulates the Navigation view controller mode, but jumps the time to be somewhat different.
Run Results
Process Overview
1. After the new project, a new Uiviewcontroller-based class is added as a second view of the multi-view;
2. In the main view, create a Uinavigationbar, a navigation bar, control page Jump
3. For added visual effects, add a background image and some text
Main codeh file
viewcontroller.h// mynav//// Created by arbboter on 14/12/9.// Copyright (c) 2014 Arbboter. All rights reserved.//#import <UIKit/UIKit.h> #import "SecondView.h" @interface Viewcontroller:uiviewcontroller { uinavigationbar* _navigationbar; uinavigationitem* _navigationitemtitle; uibarbuttonitem* _barbuttonleft; uibarbuttonitem* _barbuttonright; secondview* _nextview;} @property (nonatomic, retain) uinavigationbar* _navigationbar; @property (nonatomic, retain) uinavigationitem* _ Navigationitemtitle, @property (nonatomic, retain) uibarbuttonitem* _barbuttonleft; @property (nonatomic, retain) uibarbuttonitem* _barbuttonright; @property (nonatomic, retain) secondview* _nextview; @end
m file
viewcontroller.m//mynav////Created by Arbboter on 14/12/9.//Copyright (c) 2014 Arbboter. All rights reserved.//#import "ViewController.h" @interface Viewcontroller () @end @implementation Viewcontroller@synthesize _navigationbar, @synthesize _barbuttonleft, @synthesize _barbuttonright, @synthesize _ Navigationitemtitle; @synthesize _nextview;-(void) viewdidload{[Super Viewdidload]; Additional setup after loading the view, typically from a nib. Set Picture Self.view.backgroundColor = [Uicolor colorwithpatternimage:[uiimage imagenamed:@ "Tree_sky.jpg"]; CGFloat x = self.view.frame.origin.x; CGFloat y = self.view.frame.origin.y + 20; CGFloat w = self.view.frame.size.width; CGFloat h = 40; NSLog (@ "%.2f%.2f", Self.view.frame.size.width, Self.view.frame.size.height); Set the navigation bar Self._navigationbar = [[Uinavigationbar alloc]initwithframe:cgrectmake (x, Y, W, h)]; Self._navigationbar.translucent = NO; Self._navigationbar.backgroundcoLor = [Uicolor Clearcolor]; [Self.view Addsubview:_navigationbar]; Navigation bar "left Item,title, right item", divided into three parts self._navigationitemtitle = [[Uinavigationitem alloc] initwithtitle:@ "ordinary Road"]; [Self._navigationbar Pushnavigationitem:self._navigationitemtitle Animated:yes]; Self._barbuttonright = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@ "next.png"] style: Uibarbuttonitemstyleplain target:self Action: @selector (OnNext:)]; [Self._navigationitemtitle setrightbarbuttonitem:self._barbuttonright Animated:yes]; Self._nextview = [[Secondview alloc] init]; Some interfaces display information uitextview* textInfo = [[Uitextview alloc] Initwithframe:cgrectmake (x, Y+h, W, self.view.frame.size.height -h)]; Textinfo.backgroundcolor = [Uicolor Clearcolor]; textinfo.editable = NO; Textinfo.textcolor = [Uicolor Redcolor]; nsarray* fontlist = [Uifont familynames]; Textinfo.font = [Uifont fontwithname:[fontlist objectatindex:arc4random ()%fontlist.count] size:18]; TexTinfo.text = @ "Ordinary road-hackberry \ n" "wandering on the road \ \" Are you going to go \ \ "" Fragile pride \ "" That was my face \ \ "\ \" Boiling restless "Where are you going?" "The Mystery of the silent," "The story are you really listening?" \ n "I once crossed mountains and seas and through the sea." I used to have everything in the blink of an eye. Direction \ "" Until you see the ordinary is the only answer \ n "" \ n "" When you still Fantasize "" Your Tomorrow "" will she be okay or worse "" For me is another day \ \ \ "" I have ruined my everything just want to forever Far away from the "" I have fallen into the boundless darkness to struggle to extricate oneself, "I once like you like him like that wild flower \" "Desperate longing to cry to smile Ordinary"; [Self.view Addsubview:textinfo]; [TextInfo release];} -(Ibaction) OnNext: (ID) sender{//Jump to the next view [self Presentviewcontroller:_nextview animated:yes completion:nil];} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} -(void) dealloc{[_navigationbar release]; [_navigationitemtitle release]; [_barbuttonleft release]; [_barbuttonright release]; [_nextview release]; [Super Dealloc];} @end
Engineering Code
Customizing multiple views