代码之家  ›  专栏  ›  技术社区  ›  Rayfleck

简单uiview动画链不工作

  •  0
  • Rayfleck  · 技术社区  · 15 年前

    我尝试将uiImageView滑入uiView,同时淡入。然后我想让它褪色然后滑出来。 下面的代码应该这样做,但它没有。 相反,当LeftArrow视图滑入时,它是完全阿尔法的。所以第一个动画是跳过alpha淡入。然后第二个动画就会淡出,不会移动leftarrow视图。我尝试了很多变化(使用边界而不是帧,在类方法中执行动画(与实例方法相反),并且我无法确定为什么视图似乎随意地选择要执行的一件事情而不是另一件,或者两者兼而有之。 也许我只是需要新的眼睛。 蒂亚 迈克

    - (void) flashHorizontalArrowsForView: (UIView *)view {
    DebugLog(@" flashHorizontalArrows");
    
    
        float duration = 1.5f;
    
        // create the views
        UIImageView *leftArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"leftCouponDetailArrow.png"]];
        leftArrow.frame = CGRectMake(0 -leftArrow.image.size.width, 
                                     HORIZONTAL_ARROW_START_Y, 
                                     leftArrow.image.size.width, 
                                     leftArrow.image.size.height);
    
        [view addSubview:leftArrow];
        leftArrow.alpha =  0.0f;
    
        // animate them in...
        [UIView beginAnimations:@"foo" context:leftArrow];
        [UIView setAnimationDelay:    0.0f ];       // in seconds   
        [UIView setAnimationDuration: duration ];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        [UIView setAnimationDidStopSelector:@selector(animationReallyDidStop:finished:context:)];
        [UIView setAnimationDelegate:self];
    
        leftArrow.alpha = 1.0f;
    
        CGRect LFrame = leftArrow.frame;
        LFrame.origin.x += LFrame.size.width;  // move it in from the left.
        leftArrow.frame = LFrame;
    
        [UIView commitAnimations];
    
        // and animate them out
        // delay enough for the first one to finish  
        [UIView beginAnimations:@"bar" context:leftArrow];
        [UIView setAnimationDelay:    duration+0.05 ];       // in seconds  
        [UIView setAnimationDuration: duration ];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDidStopSelector:@selector(animationReallyDidStop:finished:context:)];
        [UIView setAnimationDelegate:self];
        leftArrow.alpha  = 0.0f;
    
        CGRect LLFrame = leftArrow.bounds;
        LLFrame.origin.x -= LLFrame.size.width;  // move it off to the left.
        leftArrow.bounds = LLFrame;
    
        [UIView commitAnimations];
    

    }

    1 回复  |  直到 15 年前
        1
  •  0
  •   Rayfleck    15 年前

    解决方案很简单——当第一个动画完成时,让它调用另一个方法,如Horizontal2,在Horizontal2中,执行“动画制作”部分。

    - (void) flashHorizontalArrowsForView: (UIView *)view{
    DebugLog(@" flashHorizontalArrows");
    self.theView = view;
    
    float duration = 1.5f;
    
    // create the views
    UIImageView *left = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"leftCouponDetailArrow.png"]];
    self.leftArrow = left;
    [left release];
    leftArrow.tag = LEFT_ARROW_TAG;
    leftArrow.frame = CGRectMake(0 -leftArrow.image.size.width, 
                                 HORIZONTAL_ARROW_START_Y, 
                                 leftArrow.image.size.width, 
                                 leftArrow.image.size.height);
    
    [theView addSubview:leftArrow];
    leftArrow.alpha =  0.0f;
    
    UIImageView *right = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rightCouponDetailArrow.png"]];
    self.rightArrow = right;
    [right release];
    rightArrow.tag = RIGHT_ARROW_TAG;
    rightArrow.frame = CGRectMake(view.frame.size.width, // -leftArrow.image.size.width, 
                                 HORIZONTAL_ARROW_START_Y, 
                                 leftArrow.image.size.width, 
                                 leftArrow.image.size.height);
    
    [theView addSubview:rightArrow];
    rightArrow.alpha =  0.0f;
    
    // --------------------------------------------
    // animate them in...
    [UIView beginAnimations:@"foo" context:nil];
    [UIView setAnimationDelay:    0.0f ];       // in seconds   
    [UIView setAnimationDuration: duration ];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDidStopSelector:@selector(horizontalPart2)];
    [UIView setAnimationDelegate:self];
    
    leftArrow.alpha  = 1.0f;
    rightArrow.alpha = 1.0f;
    
    CGRect LFrame = leftArrow.frame;
    LFrame.origin.x += LFrame.size.width;  // move it in from the left.
    leftArrow.frame = LFrame;
    
    CGRect RFrame = rightArrow.frame;
    RFrame.origin.x -= RFrame.size.width;  // move it in from the right.
    rightArrow.frame = RFrame;
    [UIView commitAnimations];
    

    }

     - (void) horizontalPart2 {
    
    // --------------------------------------------
    // and animate them out
    // delay enough for the first one to finish  
    [UIView beginAnimations:@"bar" context:nil];
    [UIView setAnimationDelay:    1.0f ];       // in seconds   
    [UIView setAnimationDuration: 3.0f ];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDidStopSelector:@selector(horizontalAnimationDidStop:finished:context:)];
    [UIView setAnimationDelegate:self];
    
    
    CGRect LLFrame = leftArrow.frame;
    LLFrame.origin.x -= LLFrame.size.width;  // move it off to the left.  // THIS IS NOT HAPPENING.
    leftArrow.frame = LLFrame;
    
    CGRect RFrame = rightArrow.frame;
    RFrame.origin.x += RFrame.size.width;
    rightArrow.frame = RFrame;
    
    leftArrow.alpha   = 0.0f;
    rightArrow.alpha  = 0.0f;
    
    [UIView commitAnimations]; 
    

    }

    推荐文章