【问题标题】:IOS8 - AutoLayout Size Class Change Notification/DelegateIOS8 - 自动布局大小类更改通知/委托
【发布时间】:2014-09-22 17:06:59
【问题描述】:

在我的应用程序中,我有一个纵向和横向大小不同的视图。当手机发生变化时,我需要让后端控制器代码触发此视图中某些图形元素的“重绘”。我该怎么做呢?是否有某种对UIView 的委托调用以了解其大小何时发生变化?

【问题讨论】:

标签: ios storyboard ios8


【解决方案1】:

您需要做的就是在您的自定义控制器中实现以下方法:

override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
    //do sth when rotated
}

【讨论】:

    【解决方案2】:

    你也可以这样写一个自定义:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(orientationChanged:)
                                                     name:UIDeviceOrientationDidChangeNotification
                                                   object:nil];
        // Do any additional setup after loading the view.
    }
    
    - (void)orientationChanged:(NSNotification *)notification
    {
        //Redraw Here
    }
    

    【讨论】:

    • 更新答案:在现代 iOS 中,UIDeviceOrientationDidChangeNotification 并不总是在屏幕宽度发生变化时调用:例如,如果应用程序在 iPad 上进入并排模式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    • 2021-12-22
    • 2013-08-24
    • 2012-10-11
    • 1970-01-01
    • 2013-10-25
    相关资源
    最近更新 更多