사용자 정의 애니메이션을 사용하여 내 맞춤형 UIViewController
("temp"라고 함)을 제공합니다.내 UIViewController가 두 번로드되는 이유는 무엇입니까? iOS7
[temp setModalPresentationStyle:UIModalPresentationCustom];
temp.transitioningDelegate = self;
[temp.view setHidden:YES];
[self presentViewController:temp animated:YES completion:nil];
내 사용자 정의 애니메이션은 화면의 왼쪽 상단 위치로 오른쪽에서 모달 뷰를 제시하십시오 UIVC가 호출됩니다. 사용자가 애니메이션을 볼 수 없도록 숨겨져 있습니다. SCREEN_HEIGHT (768) 위치에 도달하면 화면에 설정되고 가운데에서 위쪽에서 아래쪽으로 움직이는 (움직이는) 애니메이션이 적용됩니다. 목표는 위에서 아래로보기를 제시하고 위에서 아래로 (영화 장면과 같이) 닫는 것입니다.
- (void)animateTransition:(id)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
NSLog(@" fromViewController %@ ",fromViewController);
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
NSLog(@" toViewController %@ ",toViewController);
UIView *containerView = [transitionContext containerView];
if (self.presenting)
{
// set starting rect for animation toViewController.view.frame = [self rectForDismissedState:transitionContext];
[containerView addSubview:toViewController.view];
[UIView animateWithDuration:0.5
animations:^{
toViewController.view.frame = CGRectMake(-self.customSize.width, self.yValue, self.customSize.width, self.customSize.height);
}
completion:^(BOOL finished)
{
//HERE IS THE PROBLEM!!!
[toViewController.view setHidden:NO];
[UIView animateWithDuration:[self transitionDuration:transitionContext]
animations:^{
CGRect variable = [self rectForPresentedState:transitionContext];
CGRect fitToCurrentScreenResolution = CGRectMake(0, 0, variable.size.width, variable.size.height);
toViewController.view.frame = fitToCurrentScreenResolution;
}
completion:^(BOOL finished)
{
[transitionContext completeTransition:YES];
}];
}];
}
else
{
[UIView animateWithDuration:[self transitionDuration:transitionContext]
animations:^{
fromViewController.view.frame = [self rectForDismissedState:transitionContext];
}
completion:^(BOOL finished)
{
[transitionContext completeTransition:YES];
[fromViewController.view removeFromSuperview];
}
];
}
}
그리고 여기에 솔루션입니다 :이 코드는 작동하지 않는 하나입니다
- (void)animateTransition:(id)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
NSLog(@" fromViewController %@ ",fromViewController);
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
NSLog(@" toViewController %@ ",toViewController);
UIView *containerView = [transitionContext containerView];
if (self.presenting)
{
// set starting rect for animation toViewController.view.frame = [self rectForDismissedState:transitionContext];
[containerView addSubview:toViewController.view];
[UIView animateWithDuration:0.5
animations:^{
toViewController.view.frame = CGRectMake(-self.customSize.width, self.yValue, self.customSize.width, self.customSize.height);
}
];
[toViewController.view setHidden:NO];
[UIView animateWithDuration:[self transitionDuration:transitionContext]
animations:^{
CGRect variable = [self rectForPresentedState:transitionContext];
CGRect fitToCurrentScreenResolution = CGRectMake(0, 0, variable.size.width, variable.size.height);
toViewController.view.frame = fitToCurrentScreenResolution;
}
completion:^(BOOL finished)
{
[transitionContext completeTransition:YES];
}];
}
else
{
[UIView animateWithDuration:[self transitionDuration:transitionContext]
animations:^{
fromViewController.view.frame = [self rectForDismissedState:transitionContext];
}
completion:^(BOOL finished)
{
[transitionContext completeTransition:YES];
[fromViewController.view removeFromSuperview];
}
];
}
}
내 질문은 간단하다. UIVC가 두 번이나 발표되는 이유는 무엇입니까? 나는 내 사용자 지정 UIVC 게으른로드하지만 내 응용 프로그램 충돌이 UIVC = 전무는 모달 제시 될 수 없다는 것입니다 속성을 만드는 시도
.
내가이 솔루션을 시도하지만 내 문제에 적용되지 않았다
나는 또한 아무 도움으로 이런 짓을 : Calling presentModalViewController twice?
내가 해킹을 사용할 수도 있지만, 나는 왜 그것이 일어나고 있는지 알지 못할 것이다. 지금까지는 애니메이션이 완료 BLOCK에 들어가면 뷰를 다시 호출하는 것으로 보입니다.
애플 문서 말 : 애니메이션 시퀀스가 종료하면
블록 오브젝트가 실행된다. 이 블록에는 반환 값이없고 은 완료 핸들러가 호출되기 전에 애니메이션이 실제로 완료되었는지 여부를 나타내는 단일 부울 인수를 취합니다. 애니메이션의 지속 시간이 0이면 이 블록은 다음 실행 루프 사이클의 시작에서 수행됩니다. 이 매개 변수는 NULL 일 수 있습니다.
다음 실행주기가 시작된 이래로 뷰가 그려지고 있습니까? 참고 :보기가 두 번 표시되고 있다고해도 viewDidLoad 메서드는 한 번만 호출됩니다.
왜 이런 일이 일어나고 있는지 알고 싶습니다. 동일한 코드를 사용하지만 작동 솔루션이나 설명이없는 동일한 문제가있는 사용 시나리오가있는 스택 오버 플로우 관련 질문이 있습니다.
조언/의견을 주셔서 감사합니다.
안녕하세요. 체크인하고 있습니다. 이 문제에 대한 해결책을 찾았습니까? 나는 방금 비슷한 문제로 4 일간의 투쟁을 끝냈다. 귀하가 게시 한 코드가 귀하의 문제를 해결 한 "... 그리고 여기 해결책은 무엇입니까?"실제 코드입니까? –
예 코드는 iOS7에서 제대로 작동했지만 iOS8에서는 제대로 작동하지 않았습니다.작동하지 않는 코드 예제와 같이 연결된 애니메이션은 사용자 정의 전환이 발생할 때 문제를 발생시키는 것으로 보입니다. 나는 그것이 대부분의 사람들이 사용하는 커스텀 트랜지션 코드 예제 때문에 발생한다고 생각한다. 보기가 어딘가에 두 번 apearing입니다. 한 번만로드되기 때문에 두 가지 모두에 적용되는 솔루션은 viewDidLoad에 SKView를 추가하는 것이 었습니다. 결국 저를위한 속임수였습니다. –
@ banana_developer_4_iDrioid, 너무 빨리 설명해 주셔서 감사합니다! 당신이 일을 찾았다는 소식을 듣고 기쁘게 생각합니다. 정확한 원인을 찾아 내서 알아내는 것이 좋을 것 같습니다. 내 상황을 게시 할 것입니다. 누군가 다른 사람을 묶을 수도 있습니다 ... –