문제

프로그램에 다음 코드를 배치했습니다

CATransition *animation = [CATransition animation];  
[animation setDuration:0.5];  
[animation setType:kCATransitionFade];  
[animation setSubtype:kCATransitionFromLeft];  
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];  
   [[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];  

모든 것이 훌륭하게 작동하지만 프로젝트를 시뮬레이터에 구축 할 때 애니메이션이 없습니다.

이 애니메이션을 어디서 어떻게 호출합니까? 이걸 얻으면 앱 스토어에 제출할 수 있습니다!

도움이 되었습니까?

해결책

앱에 뷰가 있거나 창문이 있습니까? 다른 모든 것 아래에 애니메이션을 추가하고 있는지 궁금합니다. 대부분의 앱과 Apple의 많은 샘플에는 기본 주위가 있으며 ViewControllers 또는 기타 컨트롤러를 사용하여 모든 뷰가 추가됩니다.

또한 훨씬 간단한 시작 분석 ... Commitanimation을 사용하는 것에 대해 생각해 보셨습니까?

단지 다른 뷰의 추가와 삭제를 애니메이션하려는 경우 viewControllers와 함께이를 수행하려는 내 코드를 참조하십시오.

- (void)switchTwoViews:(UIViewController *)view1 otherView:(UIViewController *)view2 cacheTheView:(BOOL) cache;
{
    /*
     This method is called when the info or Done button is pressed.
     It flips the displayed view from the main view to the flipside view and vice-versa.
     */

    UIViewController *coming = nil;
    UIViewController *going = nil;
    UIViewAnimationTransition transition;

    [view1.view setUserInteractionEnabled: NO];
    [view2.view setUserInteractionEnabled: NO];
    if (view1.view.superview == nil) {  
        coming = view1;
        going = view2;
        transition = UIViewAnimationTransitionFlipFromLeft;
    }
    else {
        coming = view2;
        going = view1;
        transition = UIViewAnimationTransitionFlipFromRight;
    }
    //  [coming.view setFrame:CGRectMake(0, 0, 480, 320)];


    NSArray *viewArray = [[NSArray alloc] initWithObjects:coming, going, nil];
    [coming viewWillAppear:YES];
    [going viewWillDisappear:YES];
    [UIView beginAnimations:@"View Flip" context:viewArray]; {
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animationDidEnd:finished:context:)];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

        [UIView setAnimationTransition:transition forView:self.view cache:cache];
        [self.view addSubview: coming.view];
    }
    [UIView commitAnimations];

}
- (void) animationDidEnd:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    NSArray *viewArray = context;
    [((UIViewController *)[viewArray objectAtIndex:1]).view removeFromSuperview];
    [[viewArray objectAtIndex:1] viewDidDisappear:YES];
    [[viewArray objectAtIndex:0] viewDidAppear:YES];
    [[[viewArray objectAtIndex:0] view] setUserInteractionEnabled: YES];
    [viewArray release];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top