Làm thế nào để triển khai hoạt ảnh nhấp nháy trong iOS? (How to implement blink animation in iOS?)


問題描述

Làm thế nào để triển khai hoạt ảnh nhấp nháy trong iOS? (How to implement blink animation in iOS?)

I noticed interesting animation effect in iPhone application. Cell with current date is blinking/flashing when user activate application or touch Today button. 

How to implement the same effect? Is it possible to implement it without image resources (for example use only CoreGraphics)?

Thanks


參考解法

方法 1:

Use UIAnimation and animate the label's alpha property.

方法 2:

Use timer for continuous blinking effect

  mytimer = [NSTimer scheduledTimerWithTimeInterval:0.06f
                                             target:self
                                           selector:
             @selector(willStartBlinkingAnimation)
                                           userInfo:nil
                                            repeats:YES];

Write one function which will show/hide your date label. Or else you can set alpha over here, for even time set it to 0.5f, for odd time set it to 1.0f.

‑ (void) willStartBlinkingAnimation {

  [UIView animateWithDuration:1.f
                   animations:^{

                     [currentDateLabel setHidden:![currentDateLabel isHidden]];
  }];
}

When you want to stop this process, or at your viewDidUnload method, stop the process and release your timer:

[mytimer invalidate];
mytimer = nil;

Hope this will help you to fulfill your requirement.

方法 3:

I assume you mean that effect which 'shines' through the calendar day (by pressing Today).

1) Creating gradient.

Option A: To achieve this effect you should create a transparent png with the proper height of the table row. A sample img looks like this (it's only for illustration, pls create one):

Option B: create gradient using CAGradientLayer. Still you have to use an UIImageView to effectively animate the gradient on the cell's row. I would recommend Option A until you don't want to programmatically manipulate gradient visuals.

2) Placing the image on the row. 

Option A: if you are sure that this animation always takes place on the top row then you can add the gradient image simply over the table.

Option B: (what the mentioned application might uses) you have to place the gradient image inside the cell. Maybe the best choice is to use custom cells (as the mentioned app uses, see the dates on the left in boxes) where you place your gradient image on the left side of the cell (placing X coord = ‑gradient_img.width).

3) Animating gradient.

Start the animation sequence on that action what you would like to link. Eg. I think the app uses the table view's scrollViewDidEndScrollingAnimation delegate method to trigger the animation.

[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveLinear 
                 animations:^{                       
                     viewShiningImage.frame = CGRectMake(320, 0, viewShiningImage.frame.size.width, viewShiningImage.frame.size.height);
                 } 
                 completion:^(BOOL finished) {
                     viewShiningImage.frame = CGRectMake(‑viewShiningImage.frame.size.width, 0, viewShiningImage.frame.size.width, viewShiningImage.frame.size.height);
                 }
 ];

(by MartamemmonsMrunalnzs)

參考文件

  1. How to implement blink animation in iOS? (CC BY‑SA 3.0/4.0)

#animation #core-animation #iOS #core-graphics






相關問題

Iphone app PNG 序列動畫 - 如何在不崩潰的情況下以最佳方式使用 OPENgle (Iphone app PNG sequence animation - How to use OPENgle optimally without crashing)

jquery切換幻燈片和切換旋轉動畫 (jquery toggle slide and toggle rotation animate)

如何在三次貝塞爾方法上禁用 css3 過渡鼠標離開效果? (How to disable css3 transition mouseleave effect on cubic-bezier method?)

Android:故事書(動畫、聲音、圖片) (Android: Storybooks (animation, sounds, pictures))

JQuery 動畫凌亂 (JQuery Animations Messy)

拉斐爾對角變換對象和無限setIntervals (Raphael transform object diagonally and infinite setIntervals)

使用 mouseover 和 mouseout 時避免生澀的動畫 (Avoiding jerky animation when using mouseover and mouseout)

在 C 中復制 Spinrite 動畫效果 (Replicating Spinrite Animation Effect in C)

將樣式作為參數傳遞給 jquery animate (passing style as argument to jquery animate)

如何設置 UIButton 的圖像並隨後將其刪除(動畫) (How to setImage of a UIButton and subsequently remove it (animation))

單擊消息後的 MessageKit 動畫 (MessageKit animation after click on message)

連續貝塞爾動畫,不繼承變化時的緩動功能 (Continuous bezier animation without inheriting easing-function on change)







留言討論