2014-10-20 5 views
0

Google & 스택 오버플로를 모두 훑어 보았지만 한 가지 확실한 답변을 찾지 못했습니다. UIButton을 누른 후 TOCViewController로 어떻게 전환합니까? 현재 "presentViewController"를 사용하고 있지만 버튼을 두드리는 중 화면이 정지됩니다. 모든 도움을 미리 감사드립니다.iOS에서보기 컨트롤러를 전환하는 방법은 무엇입니까?

#import "SplashLoginViewController.h" 
#import <QuartzCore/QuartzCore.h> 
#import "TOCViewController.h" 

@interface SplashLoginViewController() 

@end 

@implementation SplashLoginViewController 

- (void) displayTOC { 
    TOCViewController *toc = [[TOCViewController alloc] init]; 
    [self presentViewController:toc animated:YES completion:nil]; 
} 


- (void)initializeSplashView 
{ 
    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height)]; 
    backgroundView.backgroundColor = [UIColor colorWithRed:52.0/255.0 green:170.0/255.0 blue:220.0/255.0 alpha:1.0]; 
    backgroundView.tag = 1; 
    backgroundView.layer.zPosition = 99.0f; 
    [self.view addSubview:backgroundView]; 

    UILabel *codeworksLabelView = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width, self.view.bounds.size.height/2.0 - 25.0, self.view.bounds.size.width, 50.0)]; 
    codeworksLabelView.text = @"Codeworks"; 
    codeworksLabelView.textAlignment = NSTextAlignmentCenter; 
    codeworksLabelView.textColor = [UIColor whiteColor]; 
    codeworksLabelView.font = [UIFont fontWithName:@"Montserrat" size:30.0]; 
    codeworksLabelView.tag = 2; 
    codeworksLabelView.layer.zPosition = 100.0f; 
    [self.view addSubview:codeworksLabelView]; 
} 

- (void)initializeLoginView 
{ 
    CGRect loginFrame = CGRectMake(50.0, 100.0, self.view.bounds.size.width - 100.0, 30.0); 
    CGRect passwordFrame = CGRectMake(50.0, 180.0, self.view.bounds.size.width - 100.0, 30.0); 

    UITextField *usernameInput = [[UITextField alloc] init]; 
    usernameInput.frame = loginFrame; 
    usernameInput.placeholder = @"Username"; 
    usernameInput.font = [UIFont fontWithName:@"Montserrat" size:15.0]; 
    usernameInput.returnKeyType = UIReturnKeyNext; 
    usernameInput.tag = 3; 
    usernameInput.autocorrectionType = UITextAutocorrectionTypeNo; 

    UITextField *passwordInput = [[UITextField alloc] init]; 
    passwordInput.frame = passwordFrame; 
    passwordInput.placeholder = @"Password"; 
    passwordInput.font = [UIFont fontWithName:@"Montserrat" size:15.0]; 
    passwordInput.returnKeyType = UIReturnKeyDone; 
    passwordInput.tag = 4; 
    passwordInput.secureTextEntry = YES; 

    CALayer *bottomBorder = [CALayer layer]; 
    bottomBorder.frame = CGRectMake(0.0, 29.0, usernameInput.frame.size.width, 1.0); 
    bottomBorder.backgroundColor = [UIColor blackColor].CGColor; 
    CALayer *borderCopy = [CALayer layer]; 
    borderCopy.frame = CGRectMake(0.0, 29.0, passwordInput.frame.size.width, 1.0); 
    borderCopy.backgroundColor = [UIColor blackColor].CGColor; 

    [usernameInput.layer addSublayer:bottomBorder]; 
    [passwordInput.layer addSublayer:borderCopy]; 

    [self.view addSubview:usernameInput]; 
    [self.view addSubview:passwordInput]; 

    UILabel *signInButton = [[UILabel alloc] initWithFrame:CGRectMake(0, 270, self.view.bounds.size.width, 60.0)]; 
    signInButton.font = [UIFont fontWithName:@"Montserrat" size:15.0]; 
    signInButton.text = @"Sign In"; 
    signInButton.textColor = [UIColor blackColor]; 
    signInButton.tag = 5; 
    signInButton.textAlignment = NSTextAlignmentCenter; 

    CALayer *topButtonBorder = [CALayer layer]; 
    topButtonBorder.frame = CGRectMake(0, 0, self.view.bounds.size.width, 1); 
    topButtonBorder.backgroundColor = [UIColor blackColor].CGColor; 

    CALayer *bottomButtonBorder = [CALayer layer]; 
    bottomButtonBorder.frame = CGRectMake(0, 59, self.view.bounds.size.width, 1); 
    bottomButtonBorder.backgroundColor = [UIColor blackColor].CGColor; 

    [signInButton.layer addSublayer:topButtonBorder]; 
    [signInButton.layer addSublayer:bottomButtonBorder]; 

    [self.view addSubview:signInButton]; 

    UIView *optionsDivide = [[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/2 - 0.5, self.view.bounds.size.height - 45, 1, 20)]; 
    optionsDivide.backgroundColor = [UIColor blackColor]; 
    [self.view addSubview:optionsDivide]; 

    UIButton *tos = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    UIButton *pp = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

    tos.frame = CGRectMake(self.view.bounds.size.width/2 - 115.5 , self.view.bounds.size.height - 65, 110, 60); 
    pp.frame = CGRectMake(self.view.bounds.size.width/2 + 0.5 , self.view.bounds.size.height - 65, 110, 60); 

    [tos setTitle:@"Terms of Service" forState:UIControlStateNormal]; 
    [pp setTitle:@"Privacy Policy" forState:UIControlStateNormal]; 

    pp.titleLabel.textAlignment = NSTextAlignmentLeft; 

    tos.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:12.0]; 
    pp.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:12.0]; 

    [tos addTarget:self action:@selector(displayTOC:) forControlEvents:UIControlEventTouchUpInside]; 

    [self.view addSubview:tos]; 
    [self.view addSubview:pp]; 

} 

- (void)animateSplashScreen 
{ 
    [UIView animateWithDuration:1.0 
          delay:0.0 
         options:UIViewAnimationOptionCurveEaseInOut 
        animations:^{ 
         [self.view viewWithTag:2].frame = CGRectMake(0.0, self.view.bounds.size.height/2.0 - 25.0, self.view.bounds.size.width, 50.0); 
        } 
        completion:^(BOOL finished){ 
         [self initializeLoginView]; 
         [UIView animateWithDuration:0.5 
               delay:1.0 
              options:UIViewAnimationOptionCurveEaseOut 
              animations:^{ 
               [self.view viewWithTag:1].frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 65.0); 
               [self.view viewWithTag:2].frame = CGRectMake(0.0, 15.0, self.view.bounds.size.width, 50.0); 

               ((UILabel *)[self.view viewWithTag:2]).transform = CGAffineTransformScale(((UILabel *)[self.view viewWithTag:2]).transform, 0.6, 0.6); 
              } 
              completion:^(BOOL finished){ 
               ((UILabel *)[self.view viewWithTag:2]).font = [UIFont fontWithName:@"Montserrat" size:30.0]; 

              }]; 
        }]; 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self initializeSplashView]; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
    [self animateSplashScreen]; 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    //CGPoint locationPoint = [[touches anyObject] locationInView:self.view]; 
    //CGPoint viewPoint = [[self.view viewWithTag:5] convertPoint:locationPoint fromView:self.view]; 
    //if ([[self.view viewWithTag:5] pointInside:viewPoint withEvent:event]) { 
    // [self.view viewWithTag:5].frame = CGRectMake(self.view.bounds.size.width/2 - 62.5, 254.5, 130.0, 60.0); 
    //} 
} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    //[self.view viewWithTag:5].frame = CGRectMake(self.view.bounds.size.width/2 - 67.5, 249.5, 130.0, 60.0); 
} 

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    //[self.view viewWithTag:5].frame = CGRectMake(self.view.bounds.size.width/2 - 67.5, 249.5, 130.0, 60.0); 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
} 

@end 
+0

이 질문에 대답하려면 프로젝트에서 .storyboard 파일을 사용하고 있는지 알아야합니다. –

+0

@DanielT. 나는 생각하지 않는다. 스토리 보드가 있지만 비어 있습니다. 프로그래밍 방식으로 모든 요소를 ​​추가했습니다. – jak1200

답변

0

나는, 내가 코드를 실행하고 TOC 버튼을 탭

Undeclared selector 'displayTOC:'

, 그렇지 않은 파일에 코드를 붙여 - 복사 경고는 말한다 [tos addTarget:self action:@selector(displayTOC:) forControlEvents:UIControlEventTouchUpInside];이 라인에 경고를 발견 그냥 오류와 함께 추락, 동결 :

-[ViewController displayTOC:]: unrecognized selector sent to instance ...

이 코드에서 어떤 문제가 있는지에 대한 강력한 힌트를해야합니다. 사람들에게 코드에 대해 묻는다면 모든 경고와 충돌을 밝혀야합니다.

참고, displayTOC라는 이름의 방법은 그런데 displayTOC:

라는 방법과 동일하지 않습니다, 당신이 한 애니메이션은 정말 멋지다. 잘 했어!

+0

내가 iOS를 처음 접하는 것은 꽤 분명하다. 그것을 고치는 방법에 대해 더 자세히 설명해 주시겠습니까? 콜론을 제거해야하나요? 또한 고마워, 나는 애니메이션도 정말 좋아. – jak1200

+0

방금 ​​콜론을 제거하려고했는데 효과가있었습니다. 감사! – jak1200

관련 문제