2015-01-07 6 views
0

이동 방향이 바뀌면 가로 방향으로 하나의 단추를 숨겨야하는 사용자 지정 키보드를 만들고 있는데 어떻게해야합니까? 아래 코드를 사용하고 있습니다. 이 일을 도와주세요. 풍경 또한 버튼은 viewDidLoad에서방향 변경시 스위프트 높이 변경 및 uibutton 가로 변경시 숨기기

override func updateViewConstraints() { 
    super.updateViewConstraints() 

    // Add custom view sizing constraints here 

    var currentDevice: UIDevice = UIDevice.currentDevice() 
    var orientation: UIDeviceOrientation = currentDevice.orientation 

    if orientation.isLandscape { 

    button.hidden = true 
    } 

    if orientation.isPortrait { 
     button.hidden = false 
    } 
} 
+0

여기에 코드가 없습니다. 문제가 무엇인지 설명해주십시오. 코드 작성 방법을 묻지 마십시오. –

+0

내 문제는 방향이 바뀌지 만 가로 모드에서도 버튼이 숨겨져 있지 않다. –

답변

1

그런 다음

func orientationChanged() 
{ 
    if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)) 
    {    
     button.hidden = true 
    } 

    if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)) 
    { 
     button.hidden = false 
    } 

} 

참고이 방법을 추가

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

을 넣어 세로 모드 나 가로 버튼을 숨길 볼과 볼 :

UIDevice.currentDevice().orientation은 올바른 방향을 제공하지 않을 수 있습니다. 당신은 애플의 문서에서 상태 표시 줄 방향 대신 UIApplication.sharedApplication().statusBarOrientation

를 사용할 수 있습니다

UIDevice.currentDevice().orientation

속성의 값은 장치의 현재 방향을 나타내는 상수이다. 이 값은 실제 기기의 방향을 나타내며 현재 애플리케이션의 사용자 인터페이스 방향 인 과 다를 수 있습니다. 가능한 값에 대한 설명은 "UIDeviceOrientation"을 참조하십시오.

+0

안녕하세요. 아직 작동하지 않는 버튼이 가로로 보입니다. –

+0

UIDevice.currentDevice() 대신 UIApplication.sharedApplication(). statusBarOrientation을 사용해 보셨습니까? 오리 엔테이션? – Youssef

+0

아니요 시도해 보지 않으셨습니까? –