zoukankan      html  css  js  c++  java
  • iOS---iPad开发及iPad特有的特技

    iPad开发简单介绍

    • iPad开发最大的不同在于iPhone的就是屏幕控件的适配,以及横竖屏的旋转。
    • Storyboard中得SizeClass的横竖屏配置,也不支持iPad开发。

    1.在控制器中得到设备的旋转方向

    在 iOS8及以后,屏幕就只有旋转后屏幕尺寸之分,不再是过期的旋转方向。

    • 在iOS7及以前得到屏幕旋转方向的方法
    /**
     // UIInterfaceOrientation ,屏幕方向
     UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown,
     UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
     UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
     UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
     UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
     */
    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
    	// 即将旋转执行动画
        NSLog(@"%s", __func__);
    }
    
    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
    	// 即将旋转
        NSLog(@"%s", __func__);
    }
    
    • 在iOS8以后,屏幕就只有屏幕之分,即当屏幕的宽大于高就是横屏,否则是竖屏。
      • iPad屏幕只有 (1024 * 768)横屏
      • (768 * 1024)竖屏
    - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
    {
        // 1.判断是否是横屏
        BOOL isLandscape = size.width == 1024;
    
        // 2.设置Dock的宽度和高度
        // 获取屏幕旋转动画执行的时间
        CGFloat duration = [coordinator transitionDuration];
        [UIView animateWithDuration:duration animations:^{
    
        }];
    }
    

    2.iPad中Modal弹出控制器的方式和样式

    Modal常见有4种呈现样式

    控制器属性 modalPresentationStyle
    • UIModalPresentationFullScreen :全屏显示(默认)

    • UIModalPresentationPageSheet

      • 宽度:竖屏时的宽度(768)
      • 高度:当前屏幕的高度(填充整个高度)
    • 横屏

    • 竖屏

    • UIModalPresentationFormSheet :占据屏幕中间的一小块

    • 横屏

    • 竖屏

    • UIModalPresentationCurrentContext :跟随父控制器的呈现样式

    Modal一共4种过渡样式

    控制器属性 modalTransitionStyle
    • UIModalTransitionStyleCoverVertical :从底部往上钻(默认)
    • UIModalTransitionStyleFlipHorizontal :三维翻转
    • UIModalTransitionStyleCrossDissolve :淡入淡出
    • UIModalTransitionStylePartialCurl :翻页(只显示部分,使用前提:呈现样式必须是UIModalPresentationFullScreen)
    • UIModalPresentationCustom
    • UIModalPresentationOverFullScreen
    • UIModalPresentationOverCurrentContext
    • UIModalPresentationPopover //iOS8之后过渡样式pop样式
    • UIModalPresentationNone

    3. iPad特有的UIPopoverController的使用

    案例:

    情景① 在导航栏上添加leftBarButtonItem按钮,然后弹出UIPopoverController

    • 创建UIPopoverController控制器的内容控制器添加到UIPopoverController上
    1>设置内容控制器(并需先创建内容控制器)
    • 强调UIPopoverController不是继承UIViewController,也就不具备显示功能,要设置内容,使用initWithContentViewController设置内容
    - (id)initWithContentViewController:(UIViewController *)viewController;
    
    - (void)setContentViewController:(UIViewController *)viewController animated:(BOOL)animated;
    
    @property (nonatomic, retain) UIViewController *contentViewController;
    
    2>设置尺寸
    • 设置popView的大小(默认控制器有多大就显示多大)(120, 44 * 3)
      • UIPopoverController的方法popoverContentSize
      • 内容控制器中设置的方法
        • self.preferredContentSize
        • self.contentSizeForViewInPopover /ios7过时/
    3>设置在什么地方显示
    • 调用方法
    /**
     *  弹出UIPopoverController的方法(一)
     *
     *  @param item            围绕着哪个UIBarButtonItem显示
     *  @param arrowDirections 箭头的方向
     *  @param animated        是否通过动画显示出来
     */
    - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
    

    情景② 在导航控制器的View上添加个按钮,点击,弹出一个UIPopoverController控制器,然后这个控制器再用导航控制器包装,显示二级控制器

    • 1>调用方法
    /**
     *  弹出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;
    
    • 2>控制器内,有自己的逻辑结构(和正常控制器一样可以跳转返回等)

    UIPopoverController消失,

    • 方法
    [Popover dismissPopoverAnimated:YES]
    

    4.iPad特有的UISplitViewController的使用

    a.masterViewController

    • 1>masterViewController(主要控制器)
    • 2>负责展示主要的菜单内容

    b.detailViewController

    • 1>detailViewController(详情控制器)
    • 2>负责展示详细内容
  • 相关阅读:
    为什么无法从外部访问VSTO对象?
    通过实例代码理解WPF的Dispatcher
    Silverlight打印解决方案2.0之如何自定义表体
    VSTO"无法加载自定义程序集"
    打开silverlight项目之前,您需要安装最新的Silverlight Developer运行时
    Android 3.2 联机测试adb驱动如何安装和配置?
    Android 3.2 应用程序联机(devices)测试失败提示INSTALL_FAILED_INSUFFICIENT_STORAGE
    Android sdk 3.0 sdk3.1 sdk3.2 平板开发环境安装日志
    android 蓝牙开发常见问题总结
    Pad本蓝牙模块检测
  • 原文地址:https://www.cnblogs.com/ShaoYinling/p/4790243.html
Copyright © 2011-2022 走看看