您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 開發綜合

iOS 建立帶動畫的提示 View 引導使用者

編輯:iOS 開發綜合

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

提示動畫效果

自訂提示 View

可在 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 下載:提示動畫範例

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved