在 iOS 中,可以建立自訂 UIView 並加入動畫,做成提示氣泡或引導框,協助使用者理解下一步操作。

可在 drawRect 中繪製背景圖與文字,讓提示框呈現想要的樣式。
- (id)initWithFrame:(CGRect)frame backImage:(UIImage *)image msgStr:(NSString *)txt txtColor:(UIColor *)color {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
_paopaoImage = image;
_txt = txt;
_color = color;
}
return self;
}CABasicAnimation *jumpAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
jumpAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
jumpAnimation.toValue = [NSNumber numberWithFloat:8.0f];
jumpAnimation.duration = 0.5f;
jumpAnimation.repeatCount = 10;
jumpAnimation.autoreverses = YES;
[menu.layer addAnimation:jumpAnimation forKey:@"animateLayer"];透過 autoreverses 與 repeatCount,可以讓提示框持續上下跳動,吸引注意但不會過度干擾操作。
Demo 下載:提示動畫範例