您的位置:首页 > 其它

animateWithDuration

2015-11-16 10:26 162 查看
1.frame, bounds ,center 三者之间的关系

 frame: 该view在父view坐标系统中的位置和大小。(参照点是,父亲的坐标系统)

      bounds:该view在本地坐标系统中的位置和大小。(参照点是,本地坐标系统)
      center:该view的中心点在父view坐标系统中的位置和大小。(参照电是,父亲的坐标系统)

 
搞iOS开发的童鞋基本都会用过UIView,那他的bounds和frame两个属性也不会陌生,那这两个有什么实质性的区别呢?

先看到下面的代码你肯定就明白了一些:

-(CGRect)frame{

    return CGRectMake(self.frame.origin.x,self.frame.origin.y,self.frame.size.width,self.frame.size.height);

}

-(CGRect)bounds{

    return CGRectMake(0,0,self.frame.size.width,self.frame.size.height);

}

很明显,bounds的原点是(0,0)点,而frame的原点却是任意的。
2.animateWithDuration

+ (void)animateWithDuration:([code]NSTimeInterval
)
duration
animations:(
void (^ _Nonnull)(void)
)
animations
completion:(
void (^ _Nullable)(BOOL finished)
)
completion

duration 是动画的时间,而动画效果的最终位置是在animations 里面设置的。

3.CGPointMake ,CGRectMake

CGPoint: 表示一个二维坐标系中的点
CGSize: 表示一个矩形的宽度和高度
CGRect: 表示一个矩形的位置和大小

4.代码分析CGPoint:
表示一个二维坐标系中的点

- (void)show

{

    [super show];//这个show 是否需要防止在后面呢?因为[super show]将contentview 已经加载到UIViews 上面去了。

     CGRect frame =
self.contentView.frame;

    

    self.contentView.frame =
CGRectMake(0, [UIScreen
mainScreen].bounds.size.height, frame.size.width,
frame.size.height);

    

    [UIView
animateWithDuration:0.3

                     animations:^{

                         self.contentView.frame = frame;

                     } completion:^(BOOL finished) {                  

                     }];

}

- (void)dismiss

{    [UIView
animateWithDuration:0.3

                     animations:^{

                         self.contentView.frame =
CGRectMake(0, [UIScreen
mainScreen].bounds.size.height,
self.contentView.frame.size.width,
self.contentView.frame.size.height);

                     } completion:^(BOOL finished) {

                         

                         [super
dismiss];

                     }];

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: