首页 文章

UIScrollView以横向和纵向模式缩放

提问于
浏览
0

在横向模式下我的scrollview上的zoomscale有一些问题 . 当我将iphone放在风景中时,我希望我的图像能够完美地扩展 . 当我在纵向模式下加载我的图像时,我的scrollview上的zoomcale正常工作,但当我把它放到横向时,它不会改变比例,除非我回到tableview并将iphone放在横向,然后加载图像 .

任何帮助apriciated!

我尝试过如下使用:

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

1 回答

  • 0

    添加方向更改侦听器:

    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
        }
    
    }
    

相关问题