iOS入门-基础控件总结(一)

</pre><p>新建singleViewApplication以后,系统自动创建一个UIViewController,用于控制当前界面。</p><p></p><p>UIViewController包括以下几个成员变量:</p><p><pre name="code" class="objc">@interface UIViewController : UIResponder <NSCoding, UIAppearanceContainer, UITraitEnvironment, UIContentContainer> {
    @package
    UIView           *_view;
    UITabBarItem     *_tabBarItem;
    UINavigationItem *_navigationItem;
    NSArray          *_toolbarItems;
    NSString         *_title;

暂时用到的只有_view属性,它表示一个满屏的空白视图。我们可以在图层上添加各种各样的控件,这些控件大都(还是全部?)继承自UIView。

——————————————————————————————————————————————————————————————————

UIVIew

UIView在图形方面有以下几个重要属性:

1.frame        设置视图的左上角坐标、长度、宽度。

2.bounds     设置视图的宽高。

3.center       设置视图的中点坐标。

4.transform  形变属性(不太熟),记录UIView的形变,如伸缩转角等。

@interface UIView(UIViewGeometry)

// animatable. do not use frame if view is transformed since it will not correctly reflect 
// the actual location of the view. use bounds + center instead.
@property(nonatomic) CGRect            frame;

// use bounds/center and not frame if non-identity transform. if bounds dimension is odd, center may be have fractional part
@property(nonatomic) CGRect            bounds;      // default bounds is zero origin, frame size. animatable
@property(nonatomic) CGPoint           center;      // center is center of frame. animatable
@property(nonatomic) CGAffineTransform transform;   // default is CGAffineTransformIdentity. animatable
@property(nonatomic) CGFloat           contentScaleFactor NS_AVAILABLE_IOS(4_0);

@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled;   // default is NO
@property(nonatomic,getter=isExclusiveTouch) BOOL       exclusiveTouch;         // default is NO


UIView在层次方面有以下几个重要属性:

@interface UIView(UIViewHierarchy)

@property(nonatomic,readonly) UIView       *superview;
@property(nonatomic,readonly,copy) NSArray *subviews;
@property(nonatomic,readonly) UIWindow     *window;

1.superview    父视图

2.subviews     子视图

3.window        窗口(归属于哪个窗口,我猜)

window类下有UIViewController属性,估计是项目生成时首先创建Window,再指定根页面的UIViewController,UIViewController下有UIView。

UIView的window属性估计就是指从属于哪个窗口。

——————————————————————————————————————————————————————————————————

子控件的创建流程(button为例)

    // 为按钮分配内存空间
    UIButton *btn = [[UIButton alloc]init];
    // 设置坐标位置
    btn.frame = CGRectMake(0, 0, 100, 100);
    // 设置其他属性(以背景颜色为例)
    btn.backgroundColor = [UIColor blueColor];
    // 添加目标
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    // 加入View(以根视图的UIView为例)
    [self.view addSubview:btn];

添加目标的意思是将控件关联的某一个控制器。

如上例,将Target设置为self,表示添加到当前的UIViewController,当按钮发生TouchUpInside事件,系统会调用UIViewController的btnClick方法来处理。

当需要返回该按钮的一些信息时,如按键的位置,如Tag,一般会给方法添加一个参数,如

-(void)btnClick:(UIButton*)sender;

这样当按键按下时,会调用btnClick:方法,并且把按键本身作为一个参数传进来。(至于为什么传的就是那个被按的按键,我不懂,再添加多几个参数行不行?)

消息机制实质:button大喊:发生大事啦(事件TouchUpInside),那个谁(指定控制器self),帮忙干点活(调用方法btnClick)

——————————————————————————————————————————————————————————————————

动画

添加动画,将需要缓慢变化的操作放在以下两句之间即可。

[UIView beginAnimations:nil context:nil];

// 说好的动画呢?

[UIView commitAnimations];    

其实下面这个方法比较实用:

[UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#>];

传入时间和需要变成动画的代码块,就可以美美的享受动画,一般人我不会告诉他。

这里有个小陷阱

[UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#>];
i++;
在动画完成之前,i++已经被执行,至于这个方法的实现机制是怎样的,还弄不清楚。

确实要在动画完成后再干点什么的,可以用以下方法:

[UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>];
在completion:传入动画完成后需要执行的代码块,乔布斯保证绝对是动画结束后才执行。

以下是一些UIView的基本动画:

    // 通过矩阵来形变
    btn.transform = CGAffineTransformMake(<#CGFloat a#>, <#CGFloat b#>, <#CGFloat c#>, <#CGFloat d#>, <#CGFloat tx#>, <#CGFloat ty#>);
    // 旋转角度
    btn.transform = CGAffineTransformMakeRotation(<#CGFloat angle#>);
    // 缩放
    btn.transform = CGAffineTransformMakeScale(<#CGFloat sx#>, <#CGFloat sy#>);
    // 不知道作用,呆会试试,先写完播客哈
    btn.transform = CGAffineTransformMakeTranslation(<#CGFloat tx#>, <#CGFloat ty#>);
    
    // 传入形变属性t,在t的基础上再旋转一个角度
    btn.transform = CGAffineTransformRotate(<#CGAffineTransform t#>, <#CGFloat angle#>);
    // 传入形变属性t,在t的基础上再缩放
    btn.transform = CGAffineTransformScale(<#CGAffineTransform t#>, <#CGFloat sx#>, <#CGFloat sy#>);
    //
    btn.transform = CGAffineTransformTranslate(<#CGAffineTransform t#>, <#CGFloat tx#>, <#CGFloat ty#>);


时间有点晚,明天再继续总结吧。

在培训班这几天,确实有点感慨。

身边太多零基础的同学,他们可能是因为广告而被吸引到这里,简单的认为混四个月培训班出去就能有万元高薪。

其中有一些未出校门的学生,也有不少在社会上闯荡一段时间深感前途渺茫的朋友。(我算其中之一,工作一年转行)

到底培训结束后,大家拿到怎样一张成绩单,现在还很难说。


有时候会有一种恐惧,简单的几个月,就能从零基础变成软件工程师,那科班出生的大学生,优势在哪里?

但仔细想想,又觉得不失公平。

四个月的拼搏,有时候真能顶替四年的混沌。

但四个月的混沌,终究比不过四年的混沌。

世界变化太快,快到我只能不断的选择,选最有前景的行业,最有价值的技术,但只是一直在选择。

静不下来,终究成不了事。

cocos跨平台了,HTML5据说也能结束浏览器之争了。

HTML5+CCS3+微信,基本可以取代相当一部分APP了吧?

那我这个时候才学iOS开发,又不能跨平台,有啥用呢?

一个朋友也质疑过,这么转行从零开始做iOS开发,是否有点不妥?

可能吧,但坚持下来,看看成效吧,再不济,起码学会了坚持。


今天第一次写技术博客,也第一次上传自己录制的视频(只有6分多钟,视频笔记),有点小兴奋。

就先到这吧,凌晨1:42。







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值