0

我正在编写一个调整来更改控制中心的大小。

我正在尝试根据方向设置框架。

这是代码:

%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 语句设置的内容设置框架。我做错了什么,还有其他选择吗?

4

2 回答 2

0

您可以在其父级中设置 SBControlCenterContainerView 的中心,希望这会有所帮助并祝您好运。

// In Parent UIViewController
self.sBControlCenterContainerView.center = self.view.center;
于 2016-07-20T22:44:33.100 回答
0

避免使用[[UIDevice currentDevice] orientation.... 这是硬件方向,并不总是反映用户界面的真实状态。改为使用UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]

最后,您应该真正使用自动布局,而不是像那样直接操作框架。

于 2016-07-20T22:33:53.983 回答