ios - UIScrollView 横向和纵​​向模式下的缩放比例

标签 ios xcode swift uiscrollview uiimageview

我在横向模式下的 ScrollView 上的缩放比例遇到一些问题。当我将 iPhone 横向放置时,我希望图像能完美缩放。当我以纵向模式加载图像时,我的 ScrollView 上的缩放比例工作正常,但是当我将其置于横向模式时,它不会改变比例,除非我返回桌面 View 并将 iphone 置于横向模式,然后加载图像。

如有任何帮助,请感谢!

我尝试过使用例如:

if (UIDeviceOrientationIsLandscape(UIDevice .currentDevice().orientation))
    {
        scrollView.zoomScale = 0.50
    }


    if (UIDeviceOrientationIsPortrait(UIDevice .currentDevice().orientation))
    {
        scrollView.zoomScale = 0.25

    }

这就是我以纵向模式加载图像时的样子:

This is how

这就是我在打开图片的情况下从纵向模式旋转 iPhone 时的样子(我希望它如下图所示):

enter image description here

这就是我以横向模式加载图像时的样子:

enter image description here

最佳答案

添加方向变化监听器:

NSNotificationCenter.defaultCenter().addObserver(self, selector: "deviceDidRotate", name: UIDeviceOrientationDidChangeNotification, object: nil)

然后实现deviceDidRotate方法:

func deviceDidRotate(){

    if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)){            
        scrollView.zoomScale = 0.50
    }

    if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)){
        scrollView.zoomScale = 0.25
    }

}

关于ios - UIScrollView 横向和纵​​向模式下的缩放比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32125723/

相关文章:

ios - 旋转图像变得扭曲和模糊?

ios - 在swift4中查找按钮的文本颜色

ios - 尝试转换场景时无法将 UIView 的值转换为 SCNView

ios - MKAnnotationView : have texts below the annotationView and render the View

iphone - 是否可以使用 Microsoft 管理的 EWS 通过 MonoTouch 构建 iPhone 应用程序?

iOS - 使用优化时应用程序崩溃

ios - 边输入边搜索 Swift

ios - stringByReplacingCharactersInRange 不起作用?

ios - 如何刷新 UIStackView 中控件的内容?

ios - 如何在iphone 的NSUserDefaults 中动态生成多个 key