ios假设写一个提示带动画的View,能够来引导用户行为

Posted yutingliuyl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ios假设写一个提示带动画的View,能够来引导用户行为相关的知识,希望对你有一定的参考价值。

先上图:

技术分享


这个UIView能够这样写:

-(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;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGRect textRc = rect;
    [_paopaoImage drawInRect:rect];
    CGFontRef contextFont = CGFontCreateWithFontName((CFStringRef)[UIFont systemFontOfSize:14].fontName);
    CFRelease(contextFont);
    
    CGContextSetFontSize(context, 14.0);
    CGContextSetFillColorWithColor(context, _color.CGColor);
    textRc.origin.y += 11.0f;
    [_txt drawInRect:textRc withFont:[UIFont systemFontOfSize:14] lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentCenter];
}

然后弹出的时候:

-(void)showTipView{
    CGRect rect = [[HomePageUIManager sharedInstance] categoryTipViewFrameWhenLaunch];
    PopUpMenu* menu = [[PopUpMenu alloc] initWithFrame:rect backImage:[UIImage imageNamed:@"change_search_tip.png"] msgStr:@"打开/关闭面板" txtColor:[CCommon RGBColorFromHexString:@"#ffffff" alpha:1.0f]];
    
    [self.view addSubview:menu];
    
    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"];
}

代码能够在http://download.csdn.net/detail/baidu_nod/7629687下载






以上是关于ios假设写一个提示带动画的View,能够来引导用户行为的主要内容,如果未能解决你的问题,请参考以下文章

纯css写一个带动画的弹框 visibility + opcity

干货首发,能够清理,带动画的自己定义控件CuteEditText

android 自定义带动画的统计饼图

8102 年,如何实现带动画的折叠面板

仅用一个 HTML 标签,实现带动画的抖音 Logo

仅用一个HTML标签,实现带动画的抖音LOGO