iPhone is a mobile phone, iPad, iPad Mini is a tablet computer
iPhone和iPad开发的区别:
1.屏幕的尺寸 \\分辨率
2.UI元素的排布 \\设计
3.键盘
4.API
5.屏幕方向的支持
… …
1. Screen size\resolution
In iOS development, only need to pay attention to the following situations:
1) iPhone
3.5 inch: 320 x 480 4.0 inch: 320 x 568
4.7 inch: 375 x 667 5.5 inch: 414 x 736
2) iPad, iPad Mini
9.7 inch, 7.9 inch: 768 x 1024
2. Arrangement\design of UI elements
Because the iPad screen is larger than the iPhone and can accommodate more UI elements, the arrangement is different
3. Keyboard
The iPad's virtual keyboard has an extra button to exit the keyboard
4. iPad-specific API
4.1, iPad has some more unique classes,
For example: UIPopoverController, UISplitViewController...
For the detailed usage of some classes, please see the end of this article, which will be continuously updated later...
4.2. Differences in common APIs
Some APIs can be used on iPhone and iPad, but the display effect is different, such as UIActionSheet (iPhone on the left, iPad on the right)
5. Screen orientation support
1) iPhone supports 3 directions (does not support inverted screen)
2) iPad supports 4 directions
PS: Horizontal and vertical screen support
In general, iPhone applications have one screen orientation, either vertical screen or horizontal screen (game);
secondly, Apple's official recommendation: iPad applications preferably support both horizontal and vertical screen orientations
6. Development details
1) How to create a new iPad application
2) Apps supported by the device
can only run iPhone programs on iPhone
, and can run iPhone\iPad programs on iPad
3) The development process of
iPhone and iPad development is the same
, all the knowledge used in iPhone development can basically be used on iPad
7. Differences in the use of Modal
In iPhone development, Modal is a common way to switch controllers. The
default is to pop up from the bottom of the screen until it completely covers the content behind it ;
and in iPad development, Modal is also used very frequently.
7.1. Compared with iPhone development, Modal has more usages in iPad development
- The controller that presents the style
Modal, and the final display looks like
Modal常见有4种呈现样式
UIModalPresentationFullScreen :全屏显示(默认)
UIModalPresentationPageSheet :
宽度:竖屏时的宽度(768)
高度:当前屏幕的高度(填充整个高度)
UIModalPresentationFormSheet :占据屏幕中间的一小块
UIModalPresentationCurrentContext :跟随父控制器的呈现样式
What kind of animation is the controller coming out of the transition style Modal?
Modal一共4种过渡样式
UIModalTransitionStyleCoverVertical :从底部往上钻(默认)
UIModalTransitionStyleFlipHorizontal :三维翻转
UIModalTransitionStyleCrossDissolve :淡入淡出
UIModalTransitionStylePartialCurl :翻页(只显示部分,使用前提:呈现样式必须是UIModalPresentationFullScreen)
8. Use of UIPopoverController
8.1. Introduction
UIPopoverController is a common controller in iPad development.
Unlike other controllers, it directly inherits from NSObject, not from UIViewController;
it only occupies part of the screen space to present information and is displayed at the front of the screen
UIPopoverController expired in iOS9, replaced by popoverPresentationController.
8.2. Use steps
To display a UIPopoverController, you need to go through the following three steps:
1)设置内容控制器:
由于UIPopoverController直接继承自NSObject,不具备可视化的能力,因此UIPopoverController上面的内容必须由另外一个继承自UIViewController的控制器来提供,这个控制器称为“内容控制器”
2)设置内容的尺寸:
显示出来占据多少屏幕空间
3)设置显示的位置:
从哪个地方冒出来
- Set up the content controller
设置内容控制器有3种方法:
在初始化UIPopoverController的时候传入一个内容控制器
- (id)initWithContentViewController:(UIViewController *)viewController;
@property (nonatomic, retain) UIViewController *contentViewController;
- (void)setContentViewController:(UIViewController *)viewController animated:(BOOL)animated;
以上方法和属性都是UIPopoverController的
- Set the size of the content
设置内容的尺寸有2种方法:
@property (nonatomic) CGSize popoverContentSize;
- (void)setPopoverContentSize:(CGSize)size animated:(BOOL)animated;
以上方法和属性都是UIPopoverController的
- Setting the displayed
location There are 2 ways to set the displayed location:
第一种:围绕着一个UIBarButtonItem显示(箭头指定那个UIBarButtonItem)
/**
* 弹出UIPopoverController
*
* @param item 围绕着哪个UIBarButtonItem显示
* @param arrowDirections 箭头的方向
* @param animated 是否通过动画显示出来
*/
- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
第二种:围绕着某一块特定区域显示(箭头指定那块特定区域)
/**
* 弹出UIPopoverController
*
* @param rect 指定箭头所指区域的矩形框范围(位置和尺寸)
* @param view rect参数是以view的左上角为坐标原点(0,0)
* @param arrowDirections 箭头的方向
* @param animated 是否通过动画显示出来
*/
- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
Take a small chestnut:
If you want the arrow to point to a UIView, there are two ways, such as pointing to a button
方法1
[popover presentPopoverFromRect:button.bounds inView:button permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
方法2
[popover presentPopoverFromRect:button.frame inView:button.superview permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
8.3. Set the content size through the content controller
The content controller can set its own size displayed in the popover
在iOS 7之前
@property (nonatomic,readwrite) CGSize contentSizeForViewInPopover;
从iOS 7开始
@property (nonatomic) CGSize preferredContentSize;
以上属性都是UIViewController的
8.4. Common attributes
代理对象
@property (nonatomic, assign) id <UIPopoverControllerDelegate> delegate;
是否可见
@property (nonatomic, readonly, getter=isPopoverVisible) BOOL popoverVisible;
箭头方向
@property (nonatomic, readonly) UIPopoverArrowDirection popoverArrowDirection;
关闭popover(让popover消失)
- (void)dismissPopoverAnimated:(BOOL)animated;
8.5. Prevent clicking outside the UIPopoverController area from disappearing
By default:
as long as the UIPopoverController is displayed on the screen, all the controls behind the UIPopoverController cannot interact with the user normally by default;
click the controls outside the UIPopoverController area, and the UIPopoverController will disappear by default
To prevent UIPopoverController from disappearing when you click a control outside the UIPopoverController area, the solution is to set the passthroughViews property
@property (nonatomic, copy) NSArray *passthroughViews;
this property is to set which controls can continue to interact with the user normally when the UIPopoverController is displayed . This way, clicking controls outside the area won't make the UIPopoverController disappear
8.6, common errors
In the process of using popover, this error is often encountered
- [UIPopoverController dealloc] reached while popover is still visible.
The general meaning of the error is: the popover was destroyed when it was still visible (dealloc was called)
Conclusions that can be drawn from the error:
*当popover仍旧可见的时候,不准销毁popover对象!
在销毁popover对象之前,一定先让popover消失(不可见)*
[popover dismissPopoverAnimated:YES];
8.7. How to achieve popover effect in iPhone
UIPopoverController is a class that can only be used in iPads
To achieve popover effect in iPhone, you must customize the view, you can refer to
http://code4app.com/ios/Popover-View-in-iPhone/4fa931bd06f6e78d0f000000
http://code4app.com/ios/Popup-Menu/ 512231ac6803fa9e08000000
9. Use of UISplitViewController
a.MenuViewController
1>masterViewController (main controller)
2>Responsible for displaying the main menu content
details (emphasis)
b.DetailViewController
1> detailViewController (detail controller)
2> responsible for displaying detailed content
Author: smile Liyu
Link : https://www.jianshu.com/p/059c6d19585f