주 뷰를 보유하는 ViewController가 하나 있습니다. 이 기본보기에는 leftView 및 rightView라는 다른 두 개의보기가 있습니다.하나의 UIViewController에서 여러 뷰를 처리하는 방법
나는이 "보조"보기를 응용 프로그램 시작시 숨기고 싶습니다.이 작업을 수행하는 가장 좋은 방법은 X 축을 오프셋하는 것이라고 생각했습니다.
코드를 통해이 모든 오프셋을 수행하고 싶지만 작동하지 않습니다. 인터페이스 작성기에서만 작동합니다!
두 가지를 시도했지만 둘 다 작동하지 않았습니다.
1 비아 AppDelegate에 :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
O_GViewController *mainController = (O_GViewController *) self.window.rootViewController;
[mainController leftView].frame = CGRectMake(-211, 20, 211, 548);
[mainController rightView].frame = CGRectMake(320, 20, 320, 548);
// Override point for customization after application launch.
return YES;
}
2 비아의 ViewController는 :
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//initialize secondary views
leftView = [[UIView alloc]initWithFrame:CGRectMake(-211, 20, 211, 548)];
rightView = [[UIView alloc]initWithFrame:CGRectMake(320, 20, 320, 548)];
}
모두 "보조"뷰 ViewController.h에 leftView *와 결합하고 * rightView이다.
코드를 통해이 작업을 수행하는 방법에 대해 알고 싶습니까?
감사
사실 저는 여기에 이러한 종류의 제약 조건 조작 예제가 있습니다. https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch06p255rotationChangesInterface/ch19p593rotationChangesInterface/ViewController.m 회전에 대한 응답은 필수적이지 않습니다. 핵심은 자동 레이아웃과 일치하는 방식으로 인터페이스를 변경하기 위해 제약 조건을 안팎으로 바꾸는 방법을 보여줍니다. – matt