가로 및 세로 방향을 다르게 배치해야하는보기 컨트롤러가 있습니다. 다음 코드는 하나의 작은 것을 제외하면 거의 완벽하게 작동합니다. 이동 된 버튼 (태그가 3 인 버튼)의 경우, 다른 버튼 (태그 = 0 및 호출 (IBAction) myButton :)을 클릭하면 단추가 놓인 위치로 이동합니다 스토리 보드에. 레이블은 움직이지 않고 단추 만 움직입니다. 이는 (IBAction) myButton에 설정된 제목의 값이 버튼을 누르기 전의 값과 다른 경우에만 발생합니다.버튼이 예상대로 움직이지 않는 이유
- (IBAction)myButton:(UIButton *)sender {
UIButton *but2 = (UIButton *)[self.view viewWithTag:3];
[but2 setTitle: @"A" forState:UIControlStateNormal];
UILabel *lab =(UILabel *)[self.view viewWithTag:2];
[email protected]"B";
}
-(void)rotateViewToPortrait{
UIButton *but2 = (UIButton *)[self.view viewWithTag:3];
[but2 setFrame:CGRectMake(100, 500, but2.frame.size.width, but2.frame.size.height)];
UILabel *lab =(UILabel *)[self.view viewWithTag:2];
[lab setFrame:CGRectMake(100,550 , lab.frame.size.width, lab.frame.size.height)];
}
-(void)rotateViewToLandscape{
UIButton *but2 = (UIButton *)[self.view viewWithTag:3];
[but2 setFrame:CGRectMake(500, 100 , but2.frame.size.width, but2.frame.size.height)];
UILabel *lab =(UILabel *)[self.view viewWithTag:2];
[lab setFrame:CGRectMake(500,150 , lab.frame.size.width, lab.frame.size.height)];
}
-(void)viewDidAppear:(BOOL)animated{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if ((orientation==UIInterfaceOrientationLandscapeRight)||(orientation==UIInterfaceOrientationLandscapeLeft)) {
[self willAnimateRotationToInterfaceOrientation:UIInterfaceOrientationLandscapeRight duration:0];
} else {
[self willAnimateRotationToInterfaceOrientation:UIInterfaceOrientationPortrait duration:0];
}
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if ((toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)||(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)) {
[self rotateViewToLandscape];
} else if ((toInterfaceOrientation == UIInterfaceOrientationPortrait)||(toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){
[self rotateViewToPortrait];
}
}
Upvoted-이 문제는 즉시 해결되었습니다. 나는 어떤 제약도 사용하지 않고 있지만 xib는 "Use Auto Layout"을 체크했고 서브 뷰의 위치는 예기치 않은 방식으로 상쇄되었습니다. – bmovement