사용자 정의 UIViewController 포함을 구현 중입니다.iOS : 사용자 정의 UIViewController 억제 단추 이벤트가 작동하지 않습니다.
또한 자식보기 컨트롤러의보기 아래쪽에 단추를 추가하고 있습니다.
버튼 이 계층 구조에서 하위보기 컨트롤러에있을 때 단추 이벤트가 실행되지 않는 것이 문제입니다. 루트 수준 (parentTopVc)보다 한 수준 아래에 배치 된 경우에만 을 처리합니다.
아키텍처는 다음과 같이이다 : self.window.rootViewController = rootVc
계층 :
뿌리에있다
0 ----- rootVc
1 --- -------- parentTopVc < --- 버튼 이벤트가 발생합니다.
2 ---------------------- firstTopVc < --- 버튼 이벤트가 아닙니다. 화재
2 ---------------------- secondTopVc < --- 버튼 이벤트는
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *rootVc;
UIViewController *parentTopVc;
UIViewController *firstTopVc;
UIViewController *secondTopVc;
rootVc = [UIViewController new];
self.window.rootViewController = rootVc;
parentTopVc = [UIViewController new];
[rootVc addChildViewController:parentTopVc];
[parentTopVc didMoveToParentViewController:rootVc];
//
parentTopVc.view.translatesAutoresizingMaskIntoConstraints = NO;
[rootVc.view addConstraint:
[NSLayoutConstraint
constraintWithItem:parentTopVc.view attribute:NSLayoutAttributeCenterX
relatedBy:0
toItem:rootVc.view attribute:NSLayoutAttributeCenterX
multiplier:1 constant:0]];
[rootVc.view addConstraint:
[NSLayoutConstraint
constraintWithItem:parentTopVc.view attribute:NSLayoutAttributeTop
relatedBy:0
toItem:rootVc.view attribute:NSLayoutAttributeTop
multiplier:1 constant:50]];
[rootVc.view addConstraint:
[NSLayoutConstraint
constraintWithItem:parentTopVc.view attribute:NSLayoutAttributeLeft
relatedBy:0
toItem:rootVc.view attribute:NSLayoutAttributeLeft
multiplier:1 constant:0]];
[rootVc.view addConstraint:
[NSLayoutConstraint
constraintWithItem:parentTopVc.view attribute:NSLayoutAttributeRight
relatedBy:0
toItem:rootVc.view attribute:NSLayoutAttributeRight
multiplier:1 constant:0]];
[parentTopVc.view addConstraint:
[NSLayoutConstraint
constraintWithItem:parentTopVc.view attribute:NSLayoutAttributeHeight
relatedBy:0
toItem:nil attribute:0
multiplier:1 constant:200]];
[rootVc.view addSubview: parentTopVc.view];
parentTopVc.view.backgroundColor = [UIColor clearColor];
firstTopVc = [UIViewController new];
secondTopVc = [UIViewController new];
[parentTopVc addChildViewController:childVc];
UIView* childVcInnerFrame = [[UIView alloc] initWithFrame:CGRectMake(xc,
yc,
wc,
hc)]; //x, y, w, h
[childVc.view addSubview: childVcInnerFrame];
firstTopVc.view.translatesAutoresizingMaskIntoConstraints = NO;
[parentTopVc.view addConstraint:
[NSLayoutConstraint
constraintWithItem:firstTopVc.view attribute:NSLayoutAttributeCenterX
relatedBy:0
toItem:parentTopVc.view attribute:NSLayoutAttributeCenterX
multiplier:1 constant:0]];
[parentTopVc.view addConstraint:
[NSLayoutConstraint
constraintWithItem:firstTopVc.view attribute:NSLayoutAttributeTop
relatedBy:0
toItem:parentTopVc.view attribute:NSLayoutAttributeTop
multiplier:1 constant:0]];
// activate
[parentTopVc.view addSubview: firstTopVc.view];
[firstTopVc didMoveToParentViewController:parentTopVc];
UIView *parentTopVcBtnViewsLevel1frame = [UIView new];
// add view to root
[parentTopVcInnerframeLevel1 addSubview: parentTopVcBtnViewsLevel1frame];
UIView *vtemp1;
vtemp1 = [UIView new];
[parentTopVcBtnViewsLevel1frame addSubview: vtemp1];
vtemp1.translatesAutoresizingMaskIntoConstraints = NO;
[parentTopVcBtnViewsLevel1frame addConstraint:
[NSLayoutConstraint
constraintWithItem:vtemp1 attribute:NSLayoutAttributeLeft
relatedBy:0
toItem:parentTopVcBtnViewsLevel1frame attribute:NSLayoutAttributeLeft
multiplier:1 constant:10]];
[parentTopVcBtnViewsLevel1frame addConstraint:
[NSLayoutConstraint
constraintWithItem:vtemp1 attribute:NSLayoutAttributeTop
relatedBy:0
toItem:parentTopVcBtnViewsLevel1frame attribute:NSLayoutAttributeTop
multiplier:1 constant:10]];
//v1: W
[vtemp1 addConstraint:
[NSLayoutConstraint
constraintWithItem:vtemp1 attribute:NSLayoutAttributeWidth
relatedBy:0
toItem:nil attribute:0
multiplier:1 constant:w]];
//v1: H
[vtemp1 addConstraint:
[NSLayoutConstraint
constraintWithItem:vtemp1 attribute:NSLayoutAttributeHeight
relatedBy:0
toItem:nil attribute:0
multiplier:1 constant:h]];
// button
btnInView = [UIButton buttonWithType:UIButtonTypeCustom]; //
[btnInView setBackgroundColor:[UIColor clearColor]];
btnInView.showsTouchWhenHighlighted=YES;
[btnInView setFrame: CGRectMake(0,0,w,h)]; // set up frame
[vtemp1 addSubview:btnInView]; // place button in view
[btnInView addTarget:self action:@selector(doShowNextTopVc:)
forControlEvents:UIControlEventTouchUpInside];
}
//
-(void) doShowNextTopVc:(UIButton *)paramSender{
NSLog(@"doShowNextTopVc: %@", @"START <==");
}
AppDelegate.m을 발사하지 마십시오
doShowNextTopVc never fire
고맙습니다. 위 링크 및 기타 정보를 읽었습니다. 런타임 경고가 없으며 코드가 작동하지 않고 이벤트를 저장하고 있습니다. 루트 아래 첫 번째 레벨에서만 시작됩니다. 프로그래밍 방식으로 코드를 생성하기 때문에 NIB를 사용하지 않습니다. – thstart
childVC는 어디에 선언 되었습니까? AppDelegate의 헤더 파일에? 그렇다면 해당 코드도 제공 할 수 있습니까? – Aaron
게시하는 데 문제가 있습니다. – thstart