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

                                    UISwith 

                           

 

 

概述

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

视图的职责:
画图和动画。
布局和子视图管理。

事件处理。

 

1、创建一个视图对象

CGRect viewRect = CGRectMake(10,10,100,100);
UIView* myView = [[UIView alloc] initWithFrame:viewRect];
[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 

posted @   大树2  阅读(1132)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示