2015-08-20 75 views
0

我在橫向模式下在scrollview上的zoomscale有一些問題。當我將我的iphone放在橫向上時,我希望我的圖像能夠完美縮放。我在我的scrollview上的縮放比例工作正常,當我以縱向模式加載我的圖像時,但是當我把它放到橫向時,它不會改變比例尺,除非我回到tableview並將iphone放在橫向上,然後加載圖像。UIScrollView在橫向和縱向模式下的zoomscale

任何幫助apriciated!

我已經嘗試使用如:

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


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

    } 

這是怎麼看起來像當我加載在肖像模式下的圖像:

This is how

這是怎麼樣子的時候我將圖片從肖像模式旋轉,同時打開圖片(我希望它如下圖所示):

enter image description here

這是怎麼看起來像當我加載在橫向模式下的圖像:

enter image description here

+0

你聽取方向改變事件嗎?像'UIDevice.currentDevice()。 beginGeneratingDeviceOrientationNotifications()'等 – njuri

回答

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 
    } 

} 
+0

我可以在我的viewcontroller中添加這個嗎?因爲它給我一個線程1:信號SIGABART –

+0

在哪一行出現錯誤,這個錯誤說的是什麼? 在'viewDidLoad'和'viewDidDisappear'中添加'NSNotificationCenter.defaultCenter()。addObserver..'並添加'NSNotificationCenter.defaultCenter()。removeObserver(self)' – njuri

+0

它工作正常,但是當我現在從tableview在landscapemode中,圖像加載全部縮小,就好像它是在縱向模式下一樣。無法弄清楚爲什麼? –

相關問題