【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 { .... }
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 如何成为一名专家级的开发人员
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 【DevOps】为什么我们永远疲于奔命?
- 网络管理之IP地址篇
- 文件的读出 编辑 管理
- SQL Server 2008 R2 应用及多服务器管理
- VC下通过系统快照实现进程管理的方法
- .NET微信公众号开发之公众号消息处理
- 使用nodejs开发cli项目实例
- 使用jQuery管理选择结果
- nodejs开发微博实例
- Egret引擎开发指南之创建项目
- Android开发自学笔记(二):工程文件剖析
- Web 开发常用工具 大家自己查找下载