iPhone UIView

NSObject
    UIResponder
        UIView
            UIWindow
            UILabel
            UIPickerView
            UIProgressView
            UIImageView
            UITabBar
            UIToolBar
            UINavigateBar
            UITableViewCell
            UIActionSheet
            UIAlertView
            UIScrollView --UITableView,UITextView
            UISearchBar
            UIWebView
            UIControl
                UIButton
                UIDatePicker
                UIPageControl
                UISegmentedControl
                UITextField
                UISlider
                UISwithgj

概述

UIView对象在屏幕中定义了一个复杂区域和界面来管理这个区域的内容。

视图的职责:

  • 画图和动画。
  • 布局和子视图管理。
  • 事件处理。

1、创建一个视图对象

1 CGRect viewRect = CGRectMake(10,10,100,100);
2 UIView* myView = [[UIView alloc] initWithFrame:viewRect];
3 [self.window addSubview :myView];//将视图作为子视图添加到window中

2、动画

改变一些视图属性将会使用到动画,改变属性时创建一个动画,用于给用户传递在较短时间内的变化。UIView类做了动画展现的大部分工作,但是你仍然需要声明哪种属性改变的时候,你需要动画效果。有两种不同的类型来初始化动画。

下面的UIView属性支持动画:

frame,bounds,center,transform,alpha,backgroundColor,contentStretch

在iOS 4之后,使用block-based动画方法(推荐使用),使用 开始/提交方式(begin/commit)。

3、管理视图的层次结构

superview属性:

subviews属性:

window属性:

  • addSubview方法
  • bringSubviewToFront:(UIView *)veiw方法,将view视图移到层次结构的最顶端,使得其得以展示
  • sendSubviewToBack:(UIView *)veiw方法,和上面方法正好相反
  • removeFromSupview方法,
  • insertSubview:(UIView *)view atIndex:(Interger)index方法
  • insertSubview:(UIView *)view aboveSubview(UIView *)siblingView 方法
  • insertSubview:(UIView *)view belowSubview(UIView *)siblingView 方法
  • exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2方法
  • isDescendantOfView:(UIView *)view方法,判断view是不是指定视图的子视图

4、子视图的布局(layout)

  • layoutSubviews方法,这个方法,默认没有做任何事情,需要子类进行重写
  • setNeedsLayout方法
  • layoutIfNeeded方法,立即对子视图进行布局

5、画/更新视图

  • drawRect:(CGRect)rect方法
  • setNeedsDisplay
  • setNeedsDisplayInRect:(CGRect)invalidRect方法

6、以块展现动画的方式(animating views with block)

  • animateWithDuration:delay:options:animations:completion:
  • animateWithDuration:animations:completion:
  • animateWithDuration:animations:
  • transitionWithView:duration:options:animations:completion:
  • transitionFromView:toView:duration:options:completion:

7、在视图和坐标系统之间转换

  • convertPoint:toView
  • convetPoint:fromView
  • convertRect:toView
  • convertRect:fromView

8、跟踪视图相关的改变

  • didAddSubview:
  • willRemoveSubview:
  • willMoveToSuperview
  • didMoveToSuperview
  • willMoveToWindow:
  • didMoveToWindow
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值