IOS development-UI (6) Navigation, ios-ui
Knowledge point:
1. UINavigationController
2. UINavigationItem
3. UINavigationBar
4. UINavigationController view Switch
======================================
UINavigationController
1. What is a navigation controller?
Role: Manage view Controllers
2. Create a UINavigationController object
1) initialization method
-(Id) initWithRootViewController :( UIViewController *) rootViewController
2) UINavigationController:
(1) navigationBar (height 44)
(2) customContent-provided by custom ViewController
(3) navigationToolbar (height 44)
3. Switch the view through the UINavigationController object
1) press the View Controller Into the stack container of the navigation controller.
-(Void) pushViewController :( UIViewController *) viewController
Animated :( BOOL) animated
2) Bring the View Controller out of the navigation Controller
-(UIViewController *) popViewControllerAnimated :( BOOL) animated
======================================
UINavigationItem
UINavigationItem includes:
(1) backBarButtonItem (determined by the attribute of the top-level ctl)
(2) title/titleView (current ctl)
(3) rightBarButtonItem (current ctl)
(4) leftBarButtonItem (current ctl)
1. Relationship between UINavigationItem and UIViewController
NavigationItem is an attribute of UIViewController.
This attribute serves UINavigationController.
2. Create UIBarButtonItem
1) Create UIBarButtonSystemItem
-(Id) initWithBarButtonSystemItem :( UIBarButtonSystemItem) systemItem
Target :( id) target
Action :( SEL) action;
Self. navigationItem. leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemBookmarks target: self action: @ selector (btnAction)];
2) create UIBarButtonItem
-(Id) initWithTitle :( NSString *) title
Style :( UIBarButtonItemStyle) style
Target :( id) target
Action :( SEL) action
Self. navigationItem. rightBarButtonItem = [[UIBarButtonItem new];
3) image UIBarButtonItem Creation Method
-(Id) initWithImage :( UIImage *) image
Style :( UIBarButtonItemStyle) style
Target :( id) target
Action :( SEL) action
Self. navigationItem. backBarButtonItem = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed: @ "refresh_30"] style: UIBarButtonItemStylePlain target: nil action: nil];
3) how to add UIBarButtonItem to the left and right sides of the navigation
@ Property (nonatomic, retain) UIBarButtonItem * leftBarButtonItem
@ Property (nonatomic, retain) UIBarButtonItem * rightBarButtonItem
@ Property (nonatomic, retain) UIBarButtonItem * backBarButtonItem
Self. navigationItem. rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: B];
3. Custom UIBarButtonItem
4. Customize the titleView in the middle of the navigation
Self. navigationItem. title = @ "Controller 2 ";
5. Customize backBarButtonItem
Note: To set the backBarButtonItem of the current controller, it must be displayed in the next controller.
======================================
UINavigationBar
1. How to map to UINavigationBar
Set background image
-(Void) setBackgroundImage :( UIImage *) backgroundImage
ForBarMetrics :( UIBarMetrics) barMetrics
[Self. navigationController. navigationBar setBackgroundImage: [UIImage imageNamed: @ "1.png"] forBarMetrics: UIBarMetricsDefault];
2. How to Set UINavigationBar to set the color
@ Property (nonatomic, retain) UIColor * tintColor
@ Property (nonatomic, retain) UIColor * barTintColor
3. How to set transparent colors
1) set the UINavigationBar Style
@ Property (nonatomic, assign) UIBarStyle barStyle
Self. navigationController. navigationBar. barStyle = UIBarStyleBlack;
2) transparent
@ Property (nonatomic, assign, getter = isTranslucent) BOOL translucent
// Obtain the navigation controller that manages the current view controller (if this view controller is not managed by the navigation controller, this method returns a null pointer)
// Set the navigation bar to opaque, and the coordinate points will automatically move 64 units down
Self. navigationController. navigationBar. translucent = NO;
3) change the color of the navigation bar
@ Property (nonatomic, retain) UIColor * barTintColor
// Set the background color
Self. navigationController. navigationBar. barTintColor = [UIColor colorWithRed: arc4random () % 256/255. 0 green: arc4random () % 256/255. 0 blue: arc4random () % 256/255. 0 alpha: 1.0];
4. How to hide UINavigationBar
1) Hide without animation
@ Property (nonatomic, getter = isNavigationBarHidden) BOOL navigationBarHidden
// Display
Self. navigationController. navigationBarHidden = NO;
2) hide with animation
-(Void) setNavigationBarHidden :( BOOL) navigationBarHidden
Animated :( BOOL) animated
[Self. navigationController setNavigationBarHidden: YES animated: YES];
======================================
UINavigationController view Switch
1. Get the view array in the navigation Controller
@ Property (nonatomic, copy) NSArray * viewControllers
2. Press the View Controller Into the stack container of the navigation controller.
-(Void) pushViewController :( UIViewController *) viewController
Animated :( BOOL) animated
// View Controller into Stack
[Self. navigationController pushViewController: ctlA animated: YES];
3. Bring the View Controller out of the navigation Controller
-(UIViewController *) popViewControllerAnimated :( BOOL) animated
4. Switch to the specified View Controller (the controller must be in the stack of the current navigation Controller)
-(NSArray *) popToViewController :( UIViewController *) viewController
Animated :( BOOL) animated
5. Return to the Root View Controller.
-(NSArray *) popToRootViewControllerAnimated :( BOOL) animated