小编jr0*_*00n的帖子

willRotateToInterfaceOrientation已弃用,但不了解viewWillTransitionToSize:withTransitionCoordinator:

我将我的iPad应用程序移植到iOS8和Swift.

在肖像中,我使用根UIViewController,当de设备旋转到横向时,我转向另一个UIViewController.我提出了两个解决方案,一个基于UIDevice通知,另一个基于willRotateToInterfaceRotation.我总是试图远离观察者模式,这只是我的习惯.

Observer工作正常,但是func的UIViewController中的覆盖willRotateToInterfaceOrientation(toInterfaceOrientation:UIInterfaceOrientation,duration:NSTimeInterval)看起来更清晰;)

但现在在iOS8中该功能已被弃用,我应该使用

func viewWillTransitionToSize(_ size: CGSize,
    withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator)
Run Code Online (Sandbox Code Playgroud)

但我不知道如何使用它来获得相同的结果.

这是rootViewController:

      override func willRotateToInterfaceOrientation(
                     toInterfaceOrientation: UIInterfaceOrientation, 
                                   duration: NSTimeInterval) {

      if (toInterfaceOrientation == UIInterfaceOrientation.LandscapeLeft ||                     
         toInterfaceOrientation == UIInterfaceOrientation.LandscapeRight) {

            self.performSegueWithIdentifier("toLandscape", sender: self)

      }

    }
Run Code Online (Sandbox Code Playgroud)

UIViewControllerLanscape:

override func willRotateToInterfaceOrientation(
             toInterfaceOrientation: UIInterfaceOrientation, 
                           duration: NSTimeInterval) {

    if (toInterfaceOrientation == UIInterfaceOrientation.Portrait || 
        toInterfaceOrientation == UIInterfaceOrientation.PortraitUpsideDown) {

        self.presentingViewController?.dismissViewControllerAnimated(true,
                                                               completion: nil)

    }
}
Run Code Online (Sandbox Code Playgroud)

我不喜欢使用弃用的函数,所以我不知道该怎么办...去观察者或者什么?

这是我使用的代码(仅)根UIViewController是UIDeviceOrientationDidChangeNotification的观察者:

 override func awakeFromNib() {
    let dev = UIDevice.currentDevice()
    dev.beginGeneratingDeviceOrientationNotifications()

    let nc = NSNotificationCenter.defaultCenter()
    nc.addObserver(self, …
Run Code Online (Sandbox Code Playgroud)

uiviewcontroller ios

7
推荐指数
0
解决办法
2738
查看次数

没有Internet的Alpine Linux安装软件包(docker)

我正在尝试使用Alpine构建Docker映像,并且只需要安装一些软件包(apk add),但无需互联网,因为我们的开发环境不允许互联网连接。因此,我在/ temp中复制了apk并尝试从那里安装。就像是在文档中写的那样,添加本地包, 但它仍然尝试通过Internet来获取索引...我不想要那样。那可能吗?

FROM alpine:3.8
COPY ./apk/* /tmp/
RUN apk add --allow-untrusted --no-network --no-cache /tmp/ca-certificates-20171114-r3.apk /tmp/libcurl-7.61.1-r1.apk /tmp/libssh2-1.8.0-r3.apk /tmp/nghttp2-libs-1.32.0-r0.apk /tmp/curl-7.61.1-r1.apk

ENTRYPOINT ["/usr/bin/curl"]
Run Code Online (Sandbox Code Playgroud)

(是的,该映像在DockerHub上可用,但是我们需要自己构建它)

docker alpine-linux

4
推荐指数
1
解决办法
1682
查看次数

标签 统计

alpine-linux ×1

docker ×1

ios ×1

uiviewcontroller ×1