View Controller의 viewDidLoad 메서드 구현에 텍스트 메시지 창이 설정되어 있습니다. 특정 NSString 객체에 "YES"가 포함되어 있으면 텍스트 메시지 윈도우의 메서드를 호출하고 팝업합니다.viewDidLoad의 텍스트 메시지 창이 다른 모든 것 이후에 나타납니다.
이 모든 것이 잘 작동하지만 문제는 내 텍스트 메시지 메서드 호출이 사실상 내 viewDidLoad의 첫 번째 문제이지만 아직까지 viewDidLoad의 다른 모든 요소가 수행 된 후에 텍스트 메시지 창이 팝업된다는 것이 문제입니다.
내 viewDidLoad에서 텍스트 메시지 창 코드 아래에 AVCapture 세션을 설정하고 실행하고 카메라가 보는 내용을 보여주는 "미리보기 레이어"를 만듭니다.
이 코드가 텍스트 메시지 창 코드 아래에 있더라도 텍스트 메시지 창이 팝업되기 전에 카메라의 미리보기 레이어를 몇 초 동안 볼 수 있습니다.
여기 내 viewDidLoad 메서드 구현입니다.
- (void)viewDidLoad
{
[super viewDidLoad];
if([_justFinishedSigningUp isEqual:@"YES"]) {
[self showSMS];
}
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
_session =[[AVCaptureSession alloc]init];
[_session setSessionPreset:AVCaptureSessionPresetPhoto];
_inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error;
_deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:_inputDevice error:&error];
if([_session canAddInput:_deviceInput])
[_session addInput:_deviceInput];
_previewLayer = [[AVCaptureVideoPreviewLayer alloc]initWithSession:_session];
CALayer *rootLayer = [[self view]layer];
[rootLayer setMasksToBounds:YES];
[_previewLayer setFrame:CGRectMake(0, 0, rootLayer.bounds.size.width, rootLayer.bounds.size.height/2)];
[_previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[rootLayer insertSublayer:_previewLayer atIndex:0];
_stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
[_session addOutput:_stillImageOutput];
[_session startRunning];
}
그리고 여기에 텍스트 메시지 창을 제어 할 수 있도록하는 방법의 구현은 다음과 같습니다 :
- (void)showSMS {
if(![MFMessageComposeViewController canSendText]) {
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[warningAlert show];
return;
}
NSArray *recipents = _usersToInviteToApp;
NSString *message = _textMessageInviteText;
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setSubject:@"New Message"];
[messageController setRecipients:recipents];
[messageController setBody:message];
// Present message view controller on screen
[self presentViewController:messageController animated:YES completion:nil];
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult) result
{
switch (result) {
case MessageComposeResultCancelled:
break;
case MessageComposeResultFailed:
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to send SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[warningAlert show];
break;
}
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
애니메이션을 끄고 시도했지만 도움이되지 않았습니다. viewDidAppear을 사용하려고하면 viewDidLoad를 바꾸기 위해 그것을 사용합니까, 아니면 viewDidLoad 위에 놓아야합니까? viewDidLoad 아래에 있습니까? – user3344977
viewDidAppear이 viewDidLoad를 대체하는지 여부를 확인할 수 있습니까? – user3344977
그것은'viewDidLoad'를 대체하지 않고, 그것과 함께 작동합니다. 코드에서 물리적으로 어디에 배치해야하는지는 중요하지 않습니다. 이 게시물에서 좀 더 자세한 정보를 확인하십시오. http://stackoverflow.com/questions/5562938/looking-to-understand-the-ios-uiviewcontroller-lifecycle – Stonz2