ios 怎么让position不变 只是宽度在变。

查看:113
本文介绍了ios 怎么让position不变 只是宽度在变。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

    CABasicAnimation *leftboundsanimation = [CABasicAnimation animationWithKeyPath:@"bounds.size.width"];
    leftboundsanimation.fromValue = [NSNumber numberWithFloat:1];
    //[NSValue valueWithCGSize:CGSizeMake(1, 20)];
    leftboundsanimation.toValue   = [NSNumber numberWithFloat:animationrectwidth/2-0.5];

// [NSValue valueWithCGSize:CGSizeMake(animationrectwidth/2-0.5, 20)];

    leftboundsanimation.removedOnCompletion  =   NO;
    leftboundsanimation.fillMode =   kCAFillModeForwards;
    leftboundsanimation.duration  = 1.3;
    leftboundsanimation.beginTime   =   2.7;

解决方案

CABasicAnimation version:

How to change the width of a CALayer with animation from left to right?

CGRect bounds = self.view.bounds;
CALayer *layer = self.view.layer;
layer.position = CGPointMake(0, 0);
layer.anchorPoint = CGPointMake(0, 0);

CABasicAnimation *leftBoundsAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];
leftBoundsAnimation.duration = 1.3;
leftBoundsAnimation.toValue = [NSValue valueWithCGRect:bounds];
bounds.size.width = 0;
leftBoundsAnimation.fromValue = [NSValue valueWithCGRect:bounds];

[layer addAnimation:leftBoundsAnimation forKey:@"leftBoundsAnimation"];

UIView其实有直接提供动画方法的。
改变一个view的宽度:

CGRect frame = self.view.frame;
frame.size.width = 300;
[UIView animateWithDuration:1.3 animations:^{
    self.view.frame = frame;
}];

这篇关于ios 怎么让position不变 只是宽度在变。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆