봅니다 이것에 대한 알림을 사용 할 수 있습니다. 장치 방향이 변경 될 때마다 알림이 선택기를 호출합니다. 당신의 viewDidLoad에서
쓰기이 :
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setScreenWithDeviceOrientation:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
후 다음과 같이 선택기를 정의는 : UR 장치가 방향을 변경하면
-(void)setScreenWithDeviceOrientation:(NSNotification *)notification
{
UIDeviceOrientation orientation=[[UIDevice currentDevice] orientation];
if(orientation==UIInterfaceOrientationPortrait) //Portrait orientation
{
// setView frame for portrait mode
}
else if(orientation==UIInterfaceOrientationPortraitUpsideDown) // PortraitUpsideDown
{
// setView frame for upside down portrait mode
}
else if(orientation==UIInterfaceOrientationLandscapeLeft)
{
// setView frame for Landscape Left mode
}
else if(orientation==UIInterfaceOrientationLandscapeRight) //landscape Right
{
// setView frame for Landscape Right mode
}
else
{
NSLog(@"No Orientation");
}
}
이 방법은 매번 발사했다. 현재 방향에 따라보기를 조정해야합니다.
이 정보가 도움이되기를 바랍니다.