最近开始实习,没多少时间更新了=_=

第九课:

  1、上节课demo:Dropit完整实现

    https://github.com/NSLogMeng/Stanford_iOS7_Study/commit/cfc24c2c4300185d972cf151872d313414a48d32

  2、Autolayout

    比较简单请参照课件截图https://github.com/NSLogMeng/Stanford_iOS7_Study/blob/master/Slides/Lecture%209%20Slides.pdf

    课程实现方法为在storyboard中可视化实现,本文再介绍两种方法:

    ①NSLayoutConstraint

+(instancetype)constraintWithItem:(id)view1
attribute:(NSLayoutAttribute)attr1
relatedBy:(NSLayoutRelation)
relation toItem:(id)view2
attribute:(NSLayoutAttribute)attr2
multiplier:(CGFloat)multiplier constant:(CGFloat)c;
//约束:item1.attribute =(>=,<=related) multiplier * item2.attribute + constant //使用UIView添加约束
- (void)addConstraint:(NSLayoutConstraint *)constraint

    ②Visual Format Language(VFL)

      官方文档很简单易懂

                  语法:

含义 语法 含义 语法
水平方向 H: 关系 >=,<=,==
垂直方向 V: 空间,间隙 -
Views [view] 优先级 @value
superView |    

      举例:

    

    代码实现举例:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *button1 = [[UIButton alloc] init];
button1.backgroundColor = [self randomColor];
[button1 setTitle:@"button1" forState:UIControlStateNormal];
button1.translatesAutoresizingMaskIntoConstraints = NO;//手动创建的代码使用VFL必须更改此属性
button1.layer.cornerRadius = 4.0f;
[self.view addSubview:button1]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[button1]-|" options: metrics:nil views:NSDictionaryOfVariableBindings(button1)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[button1(width)]" options: metrics:@{@"width" : @} views:NSDictionaryOfVariableBindings(button1)]]; UIButton *button2 = [[UIButton alloc] init];
button2.backgroundColor = [self randomColor];
[button2 setTitle:@"button2" forState:UIControlStateNormal];
button2.translatesAutoresizingMaskIntoConstraints = NO;//手动创建的代码使用VFL必须更改此属性
button2.layer.cornerRadius = 4.0f;
[self.view addSubview:button2]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[button2]-|" options: metrics:nil views:NSDictionaryOfVariableBindings(button2)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[button1]-44-[button2(30)]" options: metrics:nil views:NSDictionaryOfVariableBindings(button1,button2)]]; UITabBar *tabBar = [[UITabBar alloc] init];
tabBar.barTintColor = [UIColor colorWithRed:/255.0f green:/255.0f blue:/255.0f alpha:1.0f];
tabBar.translatesAutoresizingMaskIntoConstraints = NO;//手动创建的代码使用VFL必须更改此属性 UITabBarItem *item1 = [[UITabBarItem alloc] init];
[item1 setTitle:@"item1"]; UITabBarItem *item2 = [[UITabBarItem alloc] init];
[item2 setTitle:@"item2"]; UITabBarItem *item3 = [[UITabBarItem alloc] init];
[item3 setTitle:@"item3"]; tabBar.items = @[item1,item2,item3]; [self.view addSubview:tabBar];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[tabBar]|" options: metrics:nil views:NSDictionaryOfVariableBindings(tabBar)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[tabBar(45)]|" options: metrics:nil views:NSDictionaryOfVariableBindings(tabBar)]]; [button1 addTarget:self action:@selector(touchButton1) forControlEvents:UIControlEventTouchDown]; }

        注意:①代码创建的view要加 button1.translatesAutoresizingMaskIntoConstraints = NO;才能生效

            ②metrics存储VFL中可变量的值(字典),可以参考button1的约束

            ③views参数对应VFL中View的值(通过NSDictionaryOfVariableBindings(...)实现)

  3、作业

    还没做=_=,后面补。

课程视频地址:网易公开课:http://open.163.com/movie/2014/1/B/P/M9H7S9F1H_M9H80K2BP.html

       或者iTunes U搜索standford课程

(9/18)重学Standford_iOS7开发_动画、自动布局_课程笔记的更多相关文章

  1. (1/18)重学Standford_iOS7开发_iOS概述_课程笔记

    写在前面:上次学习课程对iOS还是一知半解,由于缺乏实践,看公开课的视频有时不能很好地领会知识.带着问题去学习永远是最好的方法,接触一段时间iOS开发以后再来看斯坦福iOS公开课,又会有许多新的发现, ...

  2. (3/18)重学Standford_iOS7开发_Objective-C_课程笔记

    第三课: 本节课主要是游戏实现的demo,因此我将把课程中简单的几个编程技巧提取出来,重点介绍如何自己实现作业中的要求. 纸牌游戏实现: ①游戏的进行是模型的一部分(理解什么是模型:Model = W ...

  3. (8/18)重学Standford_iOS7开发_协议、block、动画_课程笔记

    第八课: 1.协议 另一种安全处理id类型的方式如:id <MyProtocol> obj a.声明 //协议一般放于.h文件中或者在类的.h文件中 @protocol Foo <X ...

  4. (6/18)重学Standford_iOS7开发_控制器多态性、导航控制器、选项卡栏控制器_课程笔记

    终于有时间跟新了,两周时间复(yu)习(xi)了5门考试累觉不爱...... ------------------------------------------------------------- ...

  5. (7/18)重学Standford_iOS7开发_视图、绘制、手势识别_课程笔记

    第七课: 1.View 一般来说,视图是一个构造块,代表屏幕上一块矩形区域,定义了一个坐标空间,并在其中绘制及添加触控事件等. ①视图的层级关系 一个视图只能有一个父视图,可以有多个子视图 - ( - ...

  6. (4/18)重学Standford_iOS7开发_框架和带属性字符串_课程笔记

    第四课(干货课): (最近要复习考试,有点略跟不上节奏,这节课的内容还是比较重要的,仔细理解掌握对今后的编程会有很大影响) 本节课主要涉及到Foundation和UIKit框架,基本都是概念与API知 ...

  7. (5/18)重学Standford_iOS7开发_视图控制器生命周期_课程笔记

    第五课: 1.UITextView @property (nonatomic, readonly) NSTextStorage *textStorage;//注意为只读属性,因此不能直接更改内容,NS ...

  8. (2/18)重学Standford_iOS7开发_Xcode_课程笔记

    第二课: 1.惰性初始化 -(ObjectType *)example { f(!_example) example =[[ObjectType alloc] init]; return _examp ...

  9. 重学 Java 设计模式:实战外观模式「基于SpringBoot开发门面模式中间件,统一控制接口白名单场景」

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 你感受到的容易,一定有人为你承担不容易 这句话更像是描述生活的,许许多多的磕磕绊绊总 ...

随机推荐

  1. poj 1681 Painter's Problem

    Painter's Problem 题意:给一个n*n(1 <= n <= 15)具有初始颜色(颜色只有yellow&white两种,即01矩阵)的square染色,每次对一个方格 ...

  2. ACM竞赛常用STL(二)之STL--algorithm

    <algorithm>无疑是STL 中最大的一个头文件,它是由一大堆模板函数组成的.下面列举出<algorithm>中的模板函数: adjacent_find / binary ...

  3. c++ 标准委员会网址

    c++ 标准委员会网址: http://www.open-std.org/ C++11 文档网址: http://www.open-std.org/jtc1/sc22/wg21/docs/papers ...

  4. capitalize()在Python中含义

    Python为string对象提供了转换大小写的方法:upper() 和 lower(). 还不止这些,Python还为我们提供了首字母大写,其余小写的capitalize()方法, 以及所有单词首字 ...

  5. 【原创】Matlab中plot函数全功能解析

    [原创]Matlab中plot函数全功能解析 该帖由Matlab技术论(http://www.matlabsky.com)坛原创,更多精彩内容参见http://www.matlabsky.com 功能 ...

  6. 【USACO 2012 Open】Running Laps(树状数组)

    53 奶牛赛跑 约翰有 N 头奶牛,他为这些奶牛准备了一个周长为 C 的环形跑牛场.所有奶牛从起点同时起跑,奶牛在比赛中总是以匀速前进的,第 i 头牛的速度为 Vi.只要有一头奶牛跑完 L 圈之后,比 ...

  7. SpringSecurity简单应用(二)

    这里我首先对我上一篇博文的第三个实例做一下讲解,下面是applicationContext-security.xml内容如下: <?xml version="1.0" enc ...

  8. 《attodiskbenchmarks-v2.47》说明文件

    对于用电脑方便且不喜欢在手机上乱装软件的我来说,很喜欢,特此整理,并在miui首发. 一.软件介绍 ATTO Disk Benchmark是一款电脑端使用的专业测速软件,该软件非常小巧,但却很专业,是 ...

  9. HTML标签与表格

    1.打开DREAMWEAVER,新建HTML,如下图: 2.body的属性: bgcolor 页面背景色 background    背景壁纸.图片 text  文字颜色 topmargin   上边 ...

  10. linux内核--进程地址空间(三)

    引言:上篇博文中,我们简单的介绍了Linux虚拟存储器的概念及组成情况,下面来分析分析进程的创建和终结及跟进程地址空间的联系. 这里首先介绍一个比较重要的概念:存储器映射 在Linux系统中,通过将一 ...