0

I am writing a tweak to change the size of the control center.

I am trying to set the frame depending on the orientation.

This is the code:

%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

But the frame does not change if I switch to landscape mode. It only sets the frame with what is set for the else statement. What am I doing wrong and it there an alternative?

2 Answers2

0

Avoid using [[UIDevice currentDevice] orientation.... This is the hardware orientation and does not always reflect the true state of the user interface. Use UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation] instead.

Lastly, you should really be using Auto Layout instead of manipulating frames directly like that.

jp2g
  • 682
  • 4
  • 8
0

You can just set the center of SBControlCenterContainerView in it's parent, hope this helps and good luck.

// In Parent UIViewController
self.sBControlCenterContainerView.center = self.view.center;
JingJingTao
  • 1,760
  • 17
  • 28