您的位置:首页 > 移动开发 > IOS开发

【IOS 开发学习总结-OC-60】ipad应用开发的一些知识

2015-10-20 12:13 701 查看

【IOS 开发学习总结-OC-60】ipad应用开发的一些知识

ipad与iPhone上 管理有层次的工作流的不同

iPhone上:通过NavigationController,用户可以从上一层界面A到下一层界面B,当 B 处理完后,再返回 A。

ipad上:由于 ipad 屏幕比 iPhone 大的多,所以它就没有通过NavigationController来管理这种关系。——通常是在 iPad 的左边显示一个导航列表框,当单击左边的某个导航项时,该窗口的右边将会显示该导航对应的详情。——这就是 iPad 上的专用控件:UISplitVIewController.

UISplitVIewController——ipad 专用

iPad横向时

iPad 处于横向模式,UISplitVIewController的左侧会出现320px 的侧栏——常用于显示页面导航栏。右侧通常用于显示导航栏对应的详情。



iPad纵向时

UISplitVIewController的左侧的导航栏不再固定显示在左边,而是需要单击某个工具按钮来激活它。——这时,会有个浮动窗口(popover) 来显示导航栏。



图片出自:http://course.gdou.com/blog/Blog.pzs/archive/2011/11/8/10838.html

UISplitVIewController的用法

UISplitVIewController 只是用来管理左右2个 UIviewController,并没有多大额外作用。

使用UISplitVIewController的大致步骤:

1. 创建UISplitVIewController对象,

2. 通过vIewControllers 属性为UISplitVIewController设置左右2个vIewController。

3. 为UISplitVIewController设置 delegate,该属性必须实现UISplitViewControllerDelegate协议的对象。该对象负责额处理UISplitVIewController左侧导航栏的显示和隐藏事件。

UISplitViewControllerDelegate协议中的方法。

@protocol UISplitViewControllerDelegate

@optional

// This method allows a client to update any bar button items etc.
- (void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode NS_AVAILABLE_IOS(8_0);
//将改变显示模式时

- (UISplitViewControllerDisplayMode)targetDisplayModeForActionInSplitViewController:(UISplitViewController *)svc NS_AVAILABLE_IOS(8_0);
//Asks the delegate to provide the display mode to apply when a split view controller action occurs.

// Override this method to customize the behavior of `showViewController:` on a split view controller. Return YES to indicate that you've handled
// the action yourself; return NO to cause the default behavior to be executed.
- (BOOL)splitViewController:(UISplitViewController *)splitViewController showViewController:(UIViewController *)vc sender:(nullable id)sender NS_AVAILABLE_IOS(8_0);

- (BOOL)splitViewController:(UISplitViewController *)splitViewController showDetailViewController:(UIViewController *)vc sender:(nullable id)sender NS_AVAILABLE_IOS(8_0);
//是否显示详细视图控制器

// Return the view controller which is to become the primary view controller after `splitViewController` is collapsed due to a transition to
// the horizontally-compact size class. If you return `nil`, then the argument will perform its default behavior (i.e. to use its current primary view
// controller).
- (nullable UIViewController *)primaryViewControllerForCollapsingSplitViewController:(UISplitViewController *)splitViewController NS_AVAILABLE_IOS(8_0);

// Return the view controller which is to become the primary view controller after the `splitViewController` is expanded due to a transition
// to the horizontally-regular size class. If you return `nil`, then the argument will perform its default behavior (i.e. to use its current
// primary view controller.)
- (nullable UIViewController *)primaryViewControllerForExpandingSplitViewController:(UISplitViewController *)splitViewController NS_AVAILABLE_IOS(8_0);

// This method is called when a split view controller is collapsing its children for a transition to a compact-width size class. Override this
// method to perform custom adjustments to the view controller hierarchy of the target controller.  When you return from this method, you're
// expected to have modified the `primaryViewController` so as to be suitable for display in a compact-width split view controller, potentially
// using `secondaryViewController` to do so.  Return YES to prevent UIKit from applying its default behavior; return NO to request that UIKit
// perform its default collapsing behavior.
- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController NS_AVAILABLE_IOS(8_0);

// This method is called when a split view controller is separating its child into two children for a transition from a compact-width size
// class to a regular-width size class. Override this method to perform custom separation behavior.  The controller returned from this method
// will be set as the secondary view controller of the split view controller.  When you return from this method, `primaryViewController` should
// have been configured for display in a regular-width split view controller. If you return `nil`, then `UISplitViewController` will perform
// its default behavior.
- (nullable UIViewController *)splitViewController:(UISplitViewController *)splitViewController separateSecondaryViewControllerFromPrimaryViewController:(UIViewController *)primaryViewController NS_AVAILABLE_IOS(8_0);

- (UIInterfaceOrientationMask)splitViewControllerSupportedInterfaceOrientations:(UISplitViewController *)splitViewController NS_AVAILABLE_IOS(7_0);
- (UIInterfaceOrientation)splitViewControllerPreferredInterfaceOrientationForPresentation:(UISplitViewController *)splitViewController NS_AVAILABLE_IOS(7_0);

// Called when a button should be added to a toolbar for a hidden view controller.
// Implementing this method allows the hidden view controller to be presented via a swipe gesture if 'presentsWithGesture' is 'YES' (the default).
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc NS_DEPRECATED_IOS(2_0, 8_0, "Use splitViewController:willChangeToDisplayMode: and displayModeButtonItem instead");

// Called when the view is shown again in the split view, invalidating the button and popover controller.
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem NS_DEPRECATED_IOS(2_0, 8_0, "Use splitViewController:willChangeToDisplayMode: and displayModeButtonItem instead");

// Called when the view controller is shown in a popover so the delegate can take action like hiding other popovers.
- (void)splitViewController:(UISplitViewController *)svc popoverController:(UIPopoverController *)pc willPresentViewController:(UIViewController *)aViewController NS_DEPRECATED_IOS(2_0, 8_0, "Use splitViewController:willChangeToDisplayMode: instead");

// Returns YES if a view controller should be hidden by the split view controller in a given orientation.
// (This method is only called on the leftmost view controller and only discriminates portrait from landscape.)
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation  NS_DEPRECATED_IOS(5_0, 8_0, "Use preferredDisplayMode instead");
//左侧导航栏将要显示时激发该方法

@end


UIPopoverController ——ipad 专用

UIPopoverController代表浮动导航栏。——其实就是包装一个 UIViewController作为浮动窗口。

UIPopoverController使用的大致步骤

创建一个UIPopoverController对象,指定它将要包装的视图控制器;

可根据需要,调用 popoverContentSize 属性设置UIPopoverController的大小;

调用
- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
或者
- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
方法将该浮动窗口显示出来。

用户处理完后,调用
- (void)dismissPopoverAnimated:(BOOL)animated;
方法关闭浮动窗口。

UIPopoverController的.h文件。

@interface UIPopoverController : NSObject <UIAppearanceContainer> {}

- (instancetype)initWithContentViewController:(UIViewController *)viewController;

@property (nullable, nonatomic, weak) id <UIPopoverControllerDelegate> delegate;

@property (nonatomic, strong) UIViewController *contentViewController;
- (void)setContentViewController:(UIViewController *)viewController animated:(BOOL)animated;

@property (nonatomic) CGSize popoverContentSize;
- (void)setPopoverContentSize:(CGSize)size animated:(BOOL)animated;

@property (nonatomic, readonly, getter=isPopoverVisible) BOOL popoverVisible;

@property (nonatomic, readonly) UIPopoverArrowDirection popoverArrowDirection;

@property (nullable, nonatomic, copy) NSArray<__kindof UIView *> *passthroughViews;

- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;

- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;

- (void)dismissPopoverAnimated:(BOOL)animated;

/* Set popover background color. Set to nil to use default background color. Default is nil.
*/
@property (nullable, nonatomic, copy) UIColor *backgroundColor NS_AVAILABLE_IOS(7_0);

@property (nonatomic, readwrite) UIEdgeInsets popoverLayoutMargins NS_AVAILABLE_IOS(5_0);

@property (nullable, nonatomic, readwrite, strong) Class popoverBackgroundViewClass NS_AVAILABLE_IOS(5_0);

@end

//UIPopoverControllerDelegate协议
@protocol UIPopoverControllerDelegate <NSObject>
@optional

- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController NS_DEPRECATED_IOS(3_2, 9_0);

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController NS_DEPRECATED_IOS(3_2, 9_0);

- (void)popoverController:(UIPopoverController *)popoverController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView * __nonnull * __nonnull)view NS_DEPRECATED_IOS(7_0,9_0);

@end


兼容 iPhone 与 iPad 的方法

UIDevice类中头文件中常见的方法与属性。

+ (UIDevice *)currentDevice;

@property(nonatomic,readonly,strong) NSString    *name;              // e.g. "My iPhone"
@property(nonatomic,readonly,strong) NSString    *model;             // e.g. @"iPhone", @"iPod touch"
@property(nonatomic,readonly,strong) NSString    *localizedModel;    // localized version of model
@property(nonatomic,readonly,strong) NSString    *systemName;        // e.g. @"iOS"
@property(nonatomic,readonly,strong) NSString    *systemVersion;     // e.g. @"4.0"
@property(nonatomic,readonly) UIDeviceOrientation orientation;       // return current device orientation.  this will return UIDeviceOrientationUnknown unless device orientation notifications are being generated.


UIDevice对象的UIUserInterfaceIdiom属性可返回一个枚举值,如下:

typedef NS_ENUM(NSInteger, UIUserInterfaceIdiom) {
UIUserInterfaceIdiomUnspecified = -1,
UIUserInterfaceIdiomPhone NS_ENUM_AVAILABLE_IOS(3_2), // iPhone and iPod touch style UI
UIUserInterfaceIdiomPad NS_ENUM_AVAILABLE_IOS(3_2), // iPad style UI
};


判断代码格式如下:

if ([[UIDevice currentDevice] userInterfaceIdiom]
== UIUserInterfaceIdiomPhone)
{
// 直接使用masterNavigationController作为应用窗口的根控制器
self.window.rootViewController  .....
}
// 如果运行设备为iPad
else
{
....
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios ipad应用 管理 开发