2016-07-20 12 views
0

제어 센터의 크기를 변경하기위한 조정 작업을하고 있습니다.화면이 가로로 표시되지 않는 경우 프레임 설정 iOS

방향에 따라 프레임을 설정하려고합니다.

코드입니다 :

%hook SBControlCenterContainerView 
-(void)layoutSubviews{ 
%orig; 
CGRect screenBounds = [[UIScreen mainScreen] bounds]; 
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation ]== UIDeviceOrientationLandscapeRight){ 
self.frame = CGRectMake(0, 0, (screenBounds.size.width - 20), 427); 
} else { 
self.frame = CGRectMake(0, 227, screenBounds.size.width - 20, 427); 
} 
} 
%end 

하지만 가로 모드로 전환하면 프레임이 변경되지 않습니다. else 문에 설정된 내용으로 프레임을 설정합니다. 내가 뭘 잘못하고 대체 뭐가 있니?

답변

0

[[UIDevice currentDevice] orientation...을 사용하지 마십시오. 이것은 하드웨어 방향이며 항상 사용자 인터페이스의 실제 상태를 반영하지는 않습니다. 대신 UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]을 사용하십시오.

마지막으로 직접 프레임을 조작하는 대신 자동 레이아웃을 사용해야합니다.

0

SBControlCenterContainerView의 중심을 부모에 설정하면 도움이되고 행운이 있기를 바랍니다.

// In Parent UIViewController 
self.sBControlCenterContainerView.center = self.view.center;