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
이 질문에 대답하려면 프로젝트에서 .storyboard 파일을 사용하고 있는지 알아야합니다. –
@DanielT. 나는 생각하지 않는다. 스토리 보드가 있지만 비어 있습니다. 프로그래밍 방식으로 모든 요소를 추가했습니다. – jak1200