오리엔테이션 변경을 감지하기 위해 viewWillLayoutSubviews를 사용하고 있지만 iOS 8 및 Xcode 6에서와 같이 새로운 viewWillTransitionToSize를 사용해야합니다. 내 문제는 내가 그것을 사용할 수 없다는 것입니다.viewWillLayoutSubviews를 viewWillTransitionToSize로 변환하는 방법
- (void)viewWillLayoutSubviews{
NSInteger maxQuantityForWidth = MAX(3, [self.barButtons count]);
CGFloat buttonWidth = (CGRectGetWidth(self.tabBar.bounds) - (kBarButtonSeparation * (maxQuantityForWidth - 1)))/maxQuantityForWidth;
for (NSInteger i = 0; i < [self.barButtons count]; i++) {
[self.barButtons[i] setFrame:CGRectMake(i * ((buttonWidth + kBarButtonSeparation)), 2.0, buttonWidth, CGRectGetHeight(self.tabBar.bounds) - 2.0)];
}
if ([self isShowingTabBar]) {
self.functionalityContainer.frame = CGRectMake(0.0, CGRectGetHeight(self.tabBar.bounds), CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - CGRectGetHeight(self.tabBar.bounds));
} else {
self.functionalityContainer.frame = self.view.bounds;
}
if (IS_IPAD){
[self updateToolbar];
CGRect frame = self.slidingViewController.topViewController.view.frame;
if (LANDSCAPE) {
frame.size.width = 700;
} else {
frame.size.width = 768;
}
[self.slidingViewController.topViewController.view setFrame:frame];
}
}
그것은 ECSLidingViewController를 사용하여 탐색 섹션의 일부 :
내 viewWillLayoutSubviews이다. 가로 또는 세로이 때 "이해"하지 않는 것,
- (void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self updateToolbar];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
if (IS_IPAD){
CGRect frame = self.slidingViewController.topViewController.view.frame;
if (LANDSCAPE) {
NSInteger maxQuantityForWidth = MAX(3, [self.barButtons count]);
CGFloat buttonWidth = (758 - (kBarButtonSeparation * (maxQuantityForWidth - 1)))/maxQuantityForWidth;
for (NSInteger i = 0; i < [self.barButtons count]; i++) {
[self.barButtons[i] setFrame:CGRectMake(i * ((buttonWidth + kBarButtonSeparation)), 2.0, buttonWidth, CGRectGetHeight(self.tabBar.bounds) - 2.0)];
}
frame.size.width = 768;
} else {
NSInteger maxQuantityForWidth = MAX(3, [self.barButtons count]);
CGFloat buttonWidth = (758 - (kBarButtonSeparation * (maxQuantityForWidth - 1)))/maxQuantityForWidth;
for (NSInteger i = 0; i < [self.barButtons count]; i++) {
[self.barButtons[i] setFrame:CGRectMake(i * ((buttonWidth + kBarButtonSeparation)), 2.0, buttonWidth, CGRectGetHeight(self.tabBar.bounds) - 2.0)];
}
frame.size.width = 768;
}
[self.slidingViewController.topViewController.view setFrame:frame];
}
if([self isShowingTabBar]){
[self showTabBar];
}else{
[self hideTabBar];
}
if (IS_IPAD && LANDSCAPE) {
self.slidingViewController.resetStrategy = ECNone;
[self.navigationItem setLeftBarButtonItems:@[] animated:YES];
if (!self.slidingViewController.underLeftShowing) {
[self.slidingViewController anchorTopViewTo:ECRight];
}
} else {
self.slidingViewController.resetStrategy = ECTapping | ECPanning;
[self.navigationItem setLeftBarButtonItems:@[self.displayMenuBarButtonItem] animated:YES];
[self.slidingViewController resetTopView];
}
[self.slidingViewController.topViewController.view setNeedsDisplay];
[self.functionalityNavigationController.view setNeedsDisplay];
[self.view setNeedsDisplay];
}];
NSString *orientation = [[NSString alloc]initWithFormat:@"Larghezza: %f Altezza: %f", self.view.frame.size.width, self.view.frame.size.height];
[self.view makeToast:orientation duration:3.0 position:@"bottom"];
[super viewWillTransitionToSize: size withTransitionCoordinator: coordinator];
}
을했지만 작동하지 않습니다
나는 다음 시도했다. 그것을 고치는 방법에 대한 아이디어?*** 편집 : 여기
정의 나는 질문은, 어쨌든, 적어도 iOS9 (특히 멀티 태스킹)의 도입과 함께, 그것은 약간의 "이전"인 것 같다
#define LANDSCAPE UIInterfaceOrientationIsLandscape(self.interfaceOrientation)
#define LANDSCAPE_RIGHT [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft
#define LANDSCAPE_LEFT [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight
#define PORTRAIT UIInterfaceOrientationIsPortrait(self.interfaceOrientation)
#define PORTRAIT_REVERSE [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown
문제는 포함되지 않은 LANDSCAPE 매크로에 있습니다. – jrturton
내 편집 – Enzoses
에서이 self.interfaceOrientation을 캡처하는 위치를 잘 모르시기 바랍니다. '[UIApplication sharedApplication] .statusBarOrientation'을 사용하십시오. 이것이 오리엔테이션을 제공하지 않으면 내 끝에서 테스트하지 않은 다음 UIDevice 오리엔테이션에서 사용하십시오. – Srivathsa