2014-04-01 35 views
0

我試圖在錄像機上製作一個紅點。我希望這個點突然出現並消失,每0.7秒。我嘗試的每個動畫選項都以某種方式放入或放出點。我怎麼才能讓它看起來完全消失?它看起來像UIViewAnimationOptionTransitionNone默認值與UIView.h中的UIViewAnimationOptionCurveEaseInOut相同。我怎樣才能沒有任何緩解動畫?如何在iOS中輕鬆創建動畫?

enum { 
    UIViewAnimationOptionLayoutSubviews   = 1 << 0, 
    UIViewAnimationOptionAllowUserInteraction  = 1 << 1, 
    UIViewAnimationOptionBeginFromCurrentState  = 1 << 2, 
    UIViewAnimationOptionRepeat     = 1 << 3, 
    UIViewAnimationOptionAutoreverse    = 1 << 4, 
    UIViewAnimationOptionOverrideInheritedDuration = 1 << 5, 
    UIViewAnimationOptionOverrideInheritedCurve = 1 << 6, 
    UIViewAnimationOptionAllowAnimatedContent  = 1 << 7, 
    UIViewAnimationOptionShowHideTransitionViews = 1 << 8, 
    UIViewAnimationOptionOverrideInheritedOptions = 1 << 9, 

    UIViewAnimationOptionCurveEaseInOut   = 0 << 16, 
    UIViewAnimationOptionCurveEaseIn    = 1 << 16, 
    UIViewAnimationOptionCurveEaseOut    = 2 << 16, 
    UIViewAnimationOptionCurveLinear    = 3 << 16, 

    UIViewAnimationOptionTransitionNone   = 0 << 20, 
    UIViewAnimationOptionTransitionFlipFromLeft = 1 << 20, 
    UIViewAnimationOptionTransitionFlipFromRight = 2 << 20, 
    UIViewAnimationOptionTransitionCurlUp   = 3 << 20, 
    UIViewAnimationOptionTransitionCurlDown  = 4 << 20, 
    UIViewAnimationOptionTransitionCrossDissolve = 5 << 20, 
    UIViewAnimationOptionTransitionFlipFromTop  = 6 << 20, 
    UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20, 
}; 

現在我的代碼,

[UIView animateWithDuration:0.7 
          delay:0 
         options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionTransitionNone) 
        animations:^(void){ 
         self.recordingAnimationImage.alpha=0.0; 
             } 
        completion:nil 
        ]; 

回答

3

不要動畫。如果你希望它出現,並瞬間消失,嘗試這樣的事情:

viewcontroller.m

@property (strong, nonatomic) NSTimer *timer; 

- (void)viewDidLoad { 
    if (!self.timer) { 
     self.timer = [NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(alternate) userInfo:nil repeats:YES]; 
    } 
} 

- (void)alternate { 
     self.myDotView.hidden = !self.myDotView.hidden; 
} 

- (void)viewWillDisappear { 
    [self.timer invalidate]; 
    self.timer = nil; 
} 
+0

另外,NB UIViewAnimationOptionCurveLinear提供了不帶緩動功能的動畫(在這種情況下不需要)。 –

+0

我試過線性選項,它仍然很容易... –

+0

我會試試這個,謝謝! –

0

在iOS系統7或更高版本,可以使用關鍵幀動畫。

[UIView animateKeyframesWithDuration:1.4 delay:0.0 options:UIViewKeyframeAnimationOptionRepeat animations:^{ 
    [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.0 animations:^{ 
     recordingAnimationImage.alpha = 1.0; 
    }]; 
    [UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.0 animations:^{ 
     recordingAnimationImage.alpha = 0.0; 
    }]; 
} completion:nil]; 

通過指定的一個0.5相對開始時間爲所述第二狀態的變化,這意味着它發生中途總1.4第二持續時間。通過指定0的relativeDuration,這意味着狀態之間的轉換是即時的。

0

如果您在使用雨燕3,你可以使用UIViewAnimationOptionCurveLinear(或.curveLinear的簡稱),以動畫UIView不放心或縮小:

UIView.animate(withDuration: 2, delay: 0, options: [.curveLinear], animations: { 
      //Do what you want 
     }, completion: nil) 

如果你想完成:

UIView.animate(withDuration: 2, delay: 0, options: [.curveLinear], animations: { 
     //Do what you want 
    }) { (success: Bool) in 
     //Completion here 
    }