장치 방향이 비동기 적으로 UIView를 업데이트하는 데 문제가 있습니다. I는 orientationChanged 방법에목표 c : 장치 방향으로 UIView를 비동기 적으로 업데이트하십시오.
- (void)viewDidLoad{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:UIDeviceOrientationDidChangeNotification object:nil];
[self initialize];}
아래로의 viewDidLoad에서 디바이스 배향을 구현 한 I 초기화 방법은 코드를
-(void)orientationChanged {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
if(UIInterfaceOrientationIsLandscape(orientation)){
UINib *nib = [UINib nibWithNibName:@"ConsoleViewControllerLandscape" bundle:nil];
UIView *portraitView = [[nib instantiateWithOwner:self options:nil] objectAtIndex:0];
self.view = portraitView;
[self initialize];
} else {
UINib *nib = [UINib nibWithNibName:@"ConsoleViewController" bundle:nil];
UIView *portraitView = [[nib instantiateWithOwner:self options:nil] objectAtIndex:0];
self.view = portraitView;
[self initialize];
}
따라 한 사실
[self performSelectorOnMainThread:@selector(arrangeAsynchronously) withObject:nil waitUntilDone:NO];
- (void) arrangeAsynchronously{
//Some complex calculation and finally
[self.view addSubview:imageview];
}
같은 코드 비동기 UI를 업데이트 문제는 방향 변경된 imageView가 기본보기에 추가되지 않는 경우입니다. 내가 세로보기로 시작한다고하면 세로보기로 모든 이미지보기를 볼 수 있고 가로로 변경하면보기가 비어 있습니다. 다시 portrait로 전환하면 모든 하위 뷰 즉 imageView가 올바르게 추가됩니다. 문제는 오리엔테이션이 변경되었을 때, 새로운 nib 파일을로드하지만 코드가 이전 nob 파일에서로드 된 이전 뷰를 여전히 참조하는 경우입니다. 참조를 어떻게 바꿀 수 있습니까? 이 문제는 비동기 모드에서만 발생합니다.
디바이스 회전 후 서브 뷰 위치를 계산할 때 uiview가 문제가되지 않습니다. 이전 내 코드는
CGAffineTransform inverseTransform = CGAffineTransformInvert(self.view.transform);
fixedPoint = CGPointApplyAffineTransform(fixedPoint,inverseTransform);
fixedPoint = CGPointMake(fixedPoint.x+126, fixedPoint.y-109);
이었다 그리고 나는
fixedPoint = CGPointMake(fixedPoint.x+126, fixedPoint.y-109);
로 변경하지만 여전히 나는의 AffineTransform가 waitUntilDone 작동하지 않는 이유 우둔입니다 : NO 및 waitUntilDone에서 작동 : YES.
멋진 코더입니다. 나는 너를 도우려고 노력하고있어. 내가 당신의 디자인에 문제가되는 것을 좀 더 자세하게 설명하려고 노력하겠습니다. 휴대 전화가 기울어 질 때마다 재구성한다는 viewcontroller의보기가 있습니다. 하지만 어딘가에 UIWindow 또는 다른 뷰 컨트롤러가있는 경우에도 첫 번째 뷰에 대한 참조가 있습니다. 즉, 새보기를 구성하더라도 표시되지 않습니다. 기본적으로 : 당신은 UIViewController의 뷰를 재구성해서는 안된다. 이 부분이 조금 더 명확 해지기를 바랍니다. 또한 친절하고 친절한 분위기를 유지하십시오. – EsbenB
제안 해 주신 것에 대해 감사드립니다. 문제는 자체 performSelectorOnMainThread를 사용하여 뷰를 업데이트 할 때 발생합니다. @selector (arrangeAsynchronously) withObject : nil waitUntilDone : NO]; waitUntilDone : YES 일 때 문제가 발생하지 않습니다. 즉, 문제는 뷰 프레젠테이션이 아니라 스레딩과 관련이 있습니다.그것이 의미가 있으면 알려주세요. –
perform selector의 waitUntilDone YES/NO의 차이점은 코드를 실행할 때가 아니라 작업을 수행하는 스레드가 실행될 때입니다. 내가 제안한 해결책을 시도해보십시오. 도움이되지 않으면 다음 단계를 논의 할 수 있습니다. – EsbenB