2010-11-18 73 views
0

我試圖將UIImageView滑入UIView,並在同一時間淡入。然後我希望它淡入淡出。 下面的代碼應該這樣做,但它不。 而是,leftArrow視圖在滑入時處於完全alpha狀態。因此,第一個動畫正在跳過Alpha漸入式。然後第二個動畫只是淡出它,它不會移動leftArrow視圖。我已經嘗試了很多變體(使用邊界而不是框架,在類方法(而不是實例方法)中執行動畫),並且我無法確定視圖爲什麼會隨意選擇一個要做的事而不是另一個, 。或者兩者 也許我只是需要新鮮的眼光 TIA, 邁克簡單的UIView動畫鏈不工作

- (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]; 

}

+0

順便說一句,我跑了XCode 3.2.4,而這個動畫失敗與4.1 iPhone模擬器,和3.1.3的設備。 – Rayfleck 2010-11-18 15:29:33

回答

0

解決方法很簡單 - 當第一動畫完成,有它調用另一個方法,像horizo​​ntal2,並在horizo​​ntal2 ,做animate_them_out部分。

- (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]; 

}