Build adaptive iphone and ipad device engineering

Source: Internet
Author: User

There are several areas to note: API, navigation mode, and design level

API: all use an operating system-ios, so their API is basically the same, but some are specific to the ipad, such as the Uipopovercontroller controller (used to render "floating" type of view) and

Uisplitviewcontroller Controller (for Controller for screen bar). The Uipopovercontroller view is a temporary view that, when you touch the outside of the Uipopovercontroller view, closes the view.

Uipopovercontroller Controller

Common methods:

Setcontentviewcontroller: Animated: How to set the size of the content view

presentpopoverfromrect: inview: permittedarrowdirections: Animated: A method that specifies the position of a rectangular area as an anchor point to render a popover view.

Presentpopoverfrombarbuttonitem: permittedarrowdirections: animated: Specifying a button as an anchor point to render the PopOver view method

Dismisspopoveranimated: How to turn off the PopOver view.

@property(nonatomic, readonly, getter=ispopovervisible) BOOL popovervisible; Read-only property to determine whether the PopOver view is visible

@property(nonatomic, readonly) uipopoverarrowdirection Popoverarrowdirection determines the direction of the PopOver view arrow.

Uipopovercontroller instances:

Click Show to eject the printer settings screen: Connect as:

Click Coding Show when the code implements a pop-up selectviewcontroller view:

@property (Nonatomic,strong) Uipopovercontroller *poc;

-(Ibaction) show: (ID) Sender {

Selectviewcontroller *popoverviewcontroller = [Self.storyboard instantiateviewcontrollerwithidentifier:@] Selectviewcontroller "];

if (Self.poc = = nil) {

Uinavigationcontroller *nav = [[Uinavigationcontroller Alloc]initwithrootviewcontroller:popoverviewcontroller];

Self.poc = [[Uipopovercontroller Alloc]initwithcontentviewcontroller:nav];

}

[Self.poc presentpopoverfrombarbuttonitem:sender Permittedarrowdirections:uipopoverarrowdirectionup Animated:YES] ;

}

Uisplitviewcontroller Controller

Horizontal screen Splitview, the screen is divided into two views, the right is DetailView, responsible for displaying details, the left is Masterview, which has a navigation list for the right side of the DetailView navigation. Masterview's navigation list occupies a fixed size of 320 points, in the case of vertical screen, Masterview will be hidden.

Delete the view controller generated by the template, drag split view controllers to the design interface, generate four view directors

Select the split View Controller, open its property inspector, and select the Orientation property as landspace (horizontal screen). Master view can remove the navigation controller: directly delete, re-drag the Split view controller to the table view controller, select the master view controller from the popup interface, and reconnect the view controllers.

Mastertableviewcontroller Design

#import <UIKit/UIKit.h>

#import "DetailViewController.h"

@interface Mastertableviewcontroller:uitableviewcontroller

@property (Nonatomic,strong) Nsarray *listdata;

@property (strong,nonatomic) Detailviewcontroller *detailviewcontroller;

@end

#import "MasterTableViewController.h"

@interface Mastertableviewcontroller ()

@end

@implementation Mastertableviewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Self.listdata = [[Nsarray alloc]initwithobjects:@ "Blue View" @ "Yellow view", nil];

Self.detailviewcontroller = (detailviewcontroller*) [Self.splitViewController.viewControllers lastobject];

/*

The Self.splitviewcontroller is used to obtain the column view controller where they reside. The Splitviewcontroller property is provided by the Uisplitviewcontroller class, which is used when the ipad Uisplitviewcontroller as the root view controller. The Viewcontrollers property of Uisplitviewcontroller is the Nsarray pointer, which can only save two view controllers, the first is the root view controller of master view, and the second element is the root view controller of DetailView.

*/

}

#pragma mark-table View data source

-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {

return 1;

}

-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {

return 2;

}

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {

Static NSString * Cellidentifier = @ "Cell";

UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier Forindexpath:indexpath];

if (cell = = nil) {

cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];

}

Nsinteger row = [Indexpath row];

Cell.textLabel.text = [Self.listdata objectatindex:row];

return cell;

}

-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath

{

Nsinteger row = [Indexpath row];

[Self.detailviewcontroller Updateview:row];

}

@end

#import <UIKit/UIKit.h>

#import "BlueViewController.h"

#import "YellowViewController.h"

Detailviewcontroller Design

@interface Detailviewcontroller:uiviewcontroller

@property (Nonatomic,strong) Yellowviewcontroller *yellowviewcontroller;

@property (Nonatomic,strong) Blueviewcontroller *blueviewcontroller;

-(void) Updateview: (Nsinteger) row;

@end

#import "DetailViewController.h"

@interface Detailviewcontroller ()

@end

@implementation Detailviewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Self.blueviewcontroller = [Self.storyboard instantiateviewcontrollerwithidentifier:@ "BlueViewController"];

Self.yellowviewcontroller = [Self.storyboard instantiateviewcontrollerwithidentifier:@ "YellowViewController"];

[Self.view AddSubview:self.blueViewController.view];

}

-(void) Updateview: (Nsinteger) row;

{

if (row = = 0) {

if (Self.yellowViewController.view.superview) {

[Self.yellowViewController.view Removefromsuperview];

}

if (Self.blueViewController.view.superview = = nil) {

[Self.view AddSubview:self.blueViewController.view];

}

}else{

if (Self.blueViewController.view.superview) {

[Self.blueViewController.view Removefromsuperview];

}

if (Self.yellowViewController.view.superview = = nil) {

[Self.view AddSubview:self.yellowViewController.view];

}

}

}

@end

Modal View private properties

When the ipad is flat, the modal view is only displayed in the middle of the screen, not the entire screen, which is controlled by the Modelpresentationstyle property of the modal view controller, which is defined by the enumeration type Uimodalpresentationstyle.

typedef ns_enum (Nsinteger, Uimodalpresentationstyle) {

Uimodalpresentationfullscreen = 0,//Full screen status

Uimodalpresentationpagesheet,//its width is fixed at 768 points, so the modal view when the ipad is flat screen, full screen rendering when vertical screen

Uimodalpresentationformsheet,//fixed 540*620

Uimodalpresentationcurrentcontext,//has the same rendering as the parent view controller.

Uimodalpresentationcustom,

Uimodalpresentationoverfullscreen,

Uimodalpresentationovercurrentcontext,

Uimodalpresentationpopover,

Uimodalpresentationnone =-1,

};

Build adaptive iphone and ipad device engineering

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

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.