2013-07-24 2 views
3

내가 내 부모 뷰 컨트롤러와 풍경을 통해 투명 뷰 컨트롤러를 표시하고아이 뷰 컨트롤러 방향이

childView1 *viewController = [[childView1 alloc]initWithNibName:examTFVC_NIB bundle:nil row:gesture.view.tag productID:test_productID size:testsize Duration:duration]; 
      self.modalPresentationStyle = UIModalPresentationCurrentContext; 
      self.view.alpha = 0.4f; 
      viewController.view.backgroundColor = [UIColor clearColor]; 
      viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
      [self presentViewController:viewController animated:YES completion:NULL]; 

를 사용하여 내 부모 뷰 컨트롤러에 자식 뷰 컨트롤러를 표시하고 아이폰 OS에서 변경 될 때 부모 뷰 컨트롤러를 회전하는 방법 만. 하지만 문제는 내가 왼쪽에서 오른쪽으로 또는 오른쪽에서 왼쪽으로 장치를 내 자식보기 컨트롤러 방향 변경보다 왼쪽에서 오른쪽으로 변경하지만 부모보기 컨트롤러는 같은 방향으로 유지됩니다.

자식보기 컨트롤러를 표시하지 않을 때 부모보기 컨트롤러 방향이 변경된다 자식과 함께 부모보기 컨트롤러 방향을 어떻게 바꿀 수 있습니까?

프로그래밍을 통해 오리엔테이션을 변경하려고 할 때 알림 센터를 자식에서 부모로 전달하여 방향을 변경하려고했습니다.

부모 뷰 컨트롤러

-(void)rotateParent:(NSNotification *)notification 
{ 
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI); 
self.view.transform = transform; 
NSLog(@"Parent rotate "); 
} 

에서 아이 뷰 컨트롤러

- (NSUInteger)supportedInterfaceOrientations 
{ 
NSUInteger supportedOrientations = UIInterfaceOrientationMaskLandscape; 
[[NSNotificationCenter defaultCenter] postNotificationName:@"RotateParent"object:nil]; 

return supportedOrientations; 
} 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 
- (BOOL)shouldAutorotate 
{ 

return YES; 
} 

에서

하지만 난 내 "rotateParent"방법보다 상위 뷰를 통해 내 아이를 표시하기 위해 클릭 할 때 기본적으로 한 번에 실행 얻을. 다른 해결책 ??

+0

따라서 다음 회전에서 알림을 전달할 수 없습니까? –

+0

shouldAutorotateToInterfaceOrientation – prasad

+0

@prasad에서 알림을 보내실 수 있습니까? 작동하지 않습니다. 왜냐하면 iOS 5 이상 지원했기 때문입니다.그리고 ios 6 –

답변

3
부모보기> 아이폰 OS 6.0

- (BOOL)shouldAutorotate 
{ 
     [[NSNotificationCenter defaultCenter] postNotificationName:@"RotateParent" object:nil]; 
     return YES; 
    } 

가 통지를 관찰자를 추가하기 위해 < 아이폰 OS childView1

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

[[NSNotificationCenter defaultCenter] postNotificationName:@"RotateParent"object:nil]; 
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight); 

} 

6.0

를 들어

및 회전 전류 방향에 따라 적절한 각도의 부모보기.

-(void)rotateParent:(NSNotification *)note{ 

UIDeviceOrientation orientation = [UIDevice currentDevice].orientation; 
CGFloat rotationAngle = 0; 

if (orientation == UIDeviceOrientationPortraitUpsideDown) rotationAngle = M_PI; 
else if (orientation == UIDeviceOrientationLandscapeLeft) rotationAngle = M_PI_2; 
else if (orientation == UIDeviceOrientationLandscapeRight) rotationAngle = -M_PI_2; 

[UIView animateWithDuration:0.5 animations:^{ 
    self.view.transform = CGAffineTransformMakeRotation(rotationAngle); 
    self.view.transform = CGAffineTransformMakeRotation(rotationAngle); 
    self.view.transform = CGAffineTransformMakeRotation(rotationAngle); 
} completion:nil]; 

//adjust view frame based on screen size 

if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
{ 
    self.view.bounds = CGRectMake(0.0, 0.0, 480, 320); 
} 
else 
{ 
    self.view.bounds = CGRectMake(0.0, 0.0, 320, 480); 
} 
} 

문제가 발생하면 알려주세요.

+0

내 필요에 따라 대답을 바꾸고 iOS 6 이상 6 미만에서 작동합니다. –

+0

CGAffineTransform rotateTransform = CGAffineTransformMakeRotation (90 * M_PI/180.0); –

+0

Thakyou Prasad, 저를 구해 주셨습니다. – Sabareesh

0

정확하게 문제를 이해 한 적이 있다면 UIView에서이 멋진 방법을 조사하고 싶을 것입니다.

- (void)viewWillLayoutSubviews 

뷰의 경계 변경, 뷰가 파단의 위치를 ​​조정합니다. 보기가 하위보기를 레이아웃하기 전에보기 컨트롤러가 이 변경되도록이 방법을 무시할 수 있습니다. 이 메서드의 디폴트의 구현은 아무것도 실시하지 않습니다.

따라서이 메서드는 Child View Controller를 회전 할 때마다 호출되어이 메서드에서 부모 뷰 컨트롤러에 알림을 게시 할 수 있습니다.