iOS:一些界面效果的实现

来源:互联网 发布:淘宝好友如何查看 编辑:程序博客网 时间:2024/06/05 17:44

     独立于控制器的视图/按钮

        例如一些购物车悬浮栏,在不同控制器中总是悬浮在屏幕下端,点击它可以查看已添加商品。
         方法一:使用多重窗口;扩展点可以看看《Multiple Display Programming Guide for iOS》。
    // 创建 UIWindow,设置相关属性    // <span style="font-family: Arial, Helvetica, sans-serif;">makeKeyAndVisible</span>    // window 上面添加 视图    // 自定义视图//备注,上述过程可以任意放在需要的位置,当创建UIwindow,并且makeKeyAndVisible时候,视图就显示出来了
        方法二:添加到UIWindow上;
[window addSubview:navigationController.view];[window insertSubview:disclaimerController.view aboveSubview:navigationController.view];[window makeKeyAndVisible];
         注意,目标视图 添加到window上,window的“rootViewController”的视图必须也是addSubviews到windwos,如果它是赋给window的rootViewControllrer属性,则添加到window上的视图将会看不到
          问题:只有一个视图可以接受旋转事件,Beginning with iOS 6, only the topmost view controller (alongside the UIApplication object) participates in deciding whether to rotate in response to a change of the device's orientation 换句话说,In your situation its probably the fact that you are adding the view as another subview to the window. Only the first subview gets the rotation events
          解决办法:
0.把需要旋转的放前面:What you can do is add it as a subview of the first window subview。
1.Add listener and update view
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameOrOrientationChanged:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameOrOrientationChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
2.kvo,监听前面视图的center, bounds and transform,然后相应方法update view。
            方法三:如果是navigationController是rootViewController,自定义一个VC继承系统NaviVC,然后在viewdidload里面addsubview 到self.view上面



  

0 0
原创粉丝点击