UIView is the base class for all views in iOS development, representing a rectangular area on the screen while processing the drawing and touch events for that area. Uiviewcontroller is the base class for the view controller, which handles operations such as switching between screens, providing a view management model. A Uiviewcontroller manages a hierarchy of UIView. The Rootviewcontroller is the first view controller (which can be specified in Main.storyboard) that was loaded when the iOS app was launched, showing the first interface after the app was launched successfully. As a result, switching between the various Uiviewcontroller in iOS is particularly important, which directly determines the switching effect between the various interfaces of the application. The main ways to jump are as follows:
Uitabbarcontroller
Uitabbarcontroller is mainly used for peer view jumps, application cases such as four tabs below the interface. You can select a Uiviewcontroller and add it to a tab bar in the Xcode->editor->embed in-> tab bar Controller. You can also connect to a view directly from the Uitabbarcontroller in storyboard, and select the view controllers of relationship segue.
Property
Each of the viewcontroller contained in the Tabbar corresponds to a tabbaritem, and the positions are evenly divided, displaying a maximum of 4 tabs, and then folding them up. When you set Tabbar by code, you can use Setviewcontrollers to add the specified sub-Viewcontroller as its item.
Tabbaritem has title, image, SelectedImage, Badgevalue property, and Badgevalue is the reminder number in the upper right corner of the item. The SelectedIndex and Selectedviewcontroller are positioned to the currently selected Tabbaritem.
In addition, there are viewcontrollers, Selectedviewcontroller, SelectedIndex and other attributes, meaning will not wordy.
Uitabbarcontrollerdelegate
This protocol is used to perform some additional operations when selecting a Tabbaritem, to monitor tabbar changes, or to prevent a tabbaritem from being selected.
Uinavigationcontroller Stack View Management
Uinavigationcontroller is a commonly used controller for view switching in iOS development, providing a stack-style view management approach, Rootviewcontroller at the bottom of the stack. Provides a number of methods for switching between view and management, such as
Pushviewcontroller and Popviewcontroller and so on. For more information, refer to a brief summary of the previous blog Uinavigationcontroller.
General use of Uinavigationcontroller, will automatically set the title of each view interface, the upper left corner of the back button, and the right side of the screen to slide back action. If you want to disable gesture actions such as the right-click return of the screen, you can set the following in the Viewdidappear method of the current view:
self.navigationController.interactivePopGestureRecognizer.enabledNO// 禁止右滑等手势
It is important to note that the Uinavigationcontroller is a stack-like push and pop to complete the view switch, calling methods Pushviewcontroller and Popviewcontroller. The Segue property is also set to push accordingly.
Use the Viewcontrollers property to get the current view stack.
Property
Toolbarhidden is used to hide the top navigation toolbar in Navigationcontroller. In this toolbar, we can add various bar Button item controls on our own. The common ones are leftbarbuttonitem and Rightbarbuttonitem.
Uinavigationitem is each item in the view stack. You can specify it in the storyboard or xib file, or you can create your own code and add it to Uinavigationcontroller.
Uinavigationcontrollerdelegate
This protocol provides a lot of traversal methods for view jumps in Navigationcontroller. such as: Didshowviewcontroller, Willshowviewcontroller, Animationcontrollerforoperation and so on. The enumeration uinavigationcontrolleroperation defines how the view jumps between (None, Push, Pop).
Using the nib file
The nib file is a combination of a series of UIView.
NSArray *arraymessage = [[nsbundle Mainbundle] loadnibnamed:@ "Viewmessagecenter" owner:< Span class= "hljs-literal" >nil options:nil ]; self .vmessagecenter = [arraymessage objectatindex:0 ]; self .vmessagecenter .navigationcontroller = self .navigationcontroller ; self .vmessagecenter .frame = self .bounds ;
Using Storyboard
Place a Viewcontroller in storyboard, and then call Instantiateviewcontrollerwithidentifier to load the storyboard of the corresponding ID in a storyboard file ( A collection of view collections), is also a very common way.
UIStoryboard *sb = [UIStoryboard storyboardWithName:@“Main” bundle:nil];LoginViewController *vc = [sb instantiateViewControllerWithIdentifier:@“LoginViewController”];[self.navigationControllerYES];[self.navigationControllerYES completion:nil];
Using the nib file
The
Nib file is a special type of resource file that you can save Interface Builder documents for visual editing.
Each xib file corresponds to a viewcontroller or a custom view, you can use the Loadnibnamed: method to load the nib file
NSArray *arrayMessage = [[NSBundle mainBundle] loadNibNamed:@“ViewMessageCenter” owner:nil options:nil];self.vMessageCenter = [arrayMessage objectAtIndex:0];self.vMessageCenter.navigationControllerself.navigationController;self.vMessageCenter.frameself.vMainPanel.bounds;
Segue
For two separate viewcontroller, you can specify a jump mode using segue.
such as in the storyboard, in the VC1 button on the right button, connected to the second VC, select jump mode to achieve mutual jump between the two VCs.
If you want to click on an image to achieve the VC jump? This will introduce gesture.
@property (weaknonatomicIBOutletUIImageView *imageView;
When the view is loaded, set the gesture:
self.imageView.userInteractionEnabledYES;UITapGestureRecognizer *imageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped)];[self.imageView addGestureRecognizer:imageTap];
by Addsubview
such as Self.view.addSubView (Newview) can be loaded directly uiview, using Removefromsuperview to remove the UIView.
Several ways to layout and jump between UIView in iOS