animateWithDuration

来源:互联网 发布:巨人名录数据库网站 编辑:程序博客网 时间:2024/05/01 14:02

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:(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, [UIScreenmainScreen].bounds.size.height, frame.size.width, frame.size.height);

    

    [UIViewanimateWithDuration:0.3

                     animations:^{

                         self.contentView.frame = frame;

                     } completion:^(BOOL finished) {                  

                     }];

}


- (void)dismiss

{    [UIViewanimateWithDuration:0.3

                     animations:^{

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

                     } completion:^(BOOL finished) {

                         

                         [super dismiss];

                     }];

}




0 0