我在横向模式下的 ScrollView 上的缩放比例遇到一些问题。当我将 iPhone 横向放置时,我希望图像能完美缩放。当我以纵向模式加载图像时,我的 ScrollView 上的缩放比例工作正常,但是当我将其置于横向模式时,它不会改变比例,除非我返回桌面 View 并将 iphone 置于横向模式,然后加载图像。
如有任何帮助,请感谢!
我尝试过使用例如:
if (UIDeviceOrientationIsLandscape(UIDevice .currentDevice().orientation))
{
scrollView.zoomScale = 0.50
}
if (UIDeviceOrientationIsPortrait(UIDevice .currentDevice().orientation))
{
scrollView.zoomScale = 0.25
}
这就是我以纵向模式加载图像时的样子:
这就是我在打开图片的情况下从纵向模式旋转 iPhone 时的样子(我希望它如下图所示):
这就是我以横向模式加载图像时的样子:
最佳答案
添加方向变化监听器:
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/