美文网首页
iOS开发学习随记

iOS开发学习随记

作者: 舒耀 | 来源:发表于2015-03-03 10:04 被阅读51次

    //每隔1s调用一次updateTimer方法

    timer =[NSTimerscheduledTimerWithTimeInterval:1.0ftarget:selfselector:@selector(updateTimer:) userInfo:nilrepeats:YES];

    //实现如下的下拉效果

    1.使用CABasicAnimation实现

    CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"bounds.size.height"];

    anim.duration = kDefaultAnimDuration;

    anim.delegate = self;

    anim.removedOnCompletion = NO;

    anim.fromValue = [NSNumber numberWithFloat:0];

    anim.toValue   = [NSNumber numberWithFloat:_frameView.bounds.size.height];

    [anim setValue:kValueAnimationDropDown forKey:kKeyAnimationID];

    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    anim.repeatCount = 0;

    anim.autoreverses = NO;

    anim.fillMode = kCAFillModeForwards;

    [_frameView.layer addAnimation:anim forKey:@"DropIn"];

    2.基本代码如下,在viewDidload里初始化view:

    view source

    print?

    - (void)viewDidLoad

    {

    [super viewDidLoad];

    isShow = NO;

    testView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 100, 0)];

    testView.backgroundColor = [UIColor grayColor];

    testView.clipsToBounds = YES;

    UIImageView *v = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 200)];

    v.image = [UIImage imageNamed:@"320_480_1"];

    [testView addSubview:v];

    }

    按钮触发的事件方法:

    view source

    print?

    -(IBAction)go:(id)sender

    {

    if(isShow)

    {

    [UIView animateWithDuration:0.3 animations:^void{

    testView.frame = CGRectMake(0, 100, 100, 0);

    }completion:^(BOOLfinished) {

    [testView removeFromSuperview];

    }];

    }

    else

    {

    [self.view addSubview:testView];

    [UIView animateWithDuration:0.3 animations:^void{

    testView.frame = CGRectMake(0, 100, 100, 200);

    }completion:NULL];

    }

    isShow = !isShow;

    }

    相关文章

      网友评论

          本文标题:iOS开发学习随记

          本文链接:https://www.haomeiwen.com/subject/esqyxttx.html