2016-07-20 2 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; 
関連する問題