标签:
一、@property(nonatomic,copy) NSArray *gestureRecognizers NS_AVAILABLE_IOS(3_2); 手势识别器
UIKit 中UIGestureRecognizer类的子类系列如下:
UITapGestureRecognizer – “轻击”手势。可以配置为“单击”和“连击”的识别。
UIPinchGestureRecognizer –“捏合”手势。该手势通常用于缩放视图或改变可视组件的大小。
UIPanGestureRecognizer – “平移”手势。识别拖拽或移动动作。
UISwipeGestureRecognizer – “轻扫”手势。当用户从屏幕上划过时识别为该手势。可以指定该动作的方向(上、下、左、右)。
UIRotationGestureRecognizer – “转动”手势。用户两指在屏幕上做相对环形运动。
UILongPressGestureRecognizer – “长按”手势。使用1指或多指触摸屏幕并保持一定时间。
二、- (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer NS_AVAILABLE_IOS(3_2); 绑定手势到视图
UITapGestureRecognizer * demoGesture = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerTwoTaps)] autorelease];
demoGesture.numberOfTapsRequired = 2; //二个手势
demoGesture.numberOfTouchesRequired = 1; //一个手指
[insertDemoOne addGestureRecognizer:demoGesture];
三、- (void)removeGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer NS_AVAILABLE_IOS(3_2); 从视图中分离手势
[insertDemoOne removeGestureRecognizer:demoGesture];
四、- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer NS_AVAILABLE_IOS(6_0); 手势识别处理方式在gesture recognizer视图转出《UIGestureRecognizerStatePossible》状态时调用,
如果返回NO,则转换到《UIGestureRecognizerStateFailed》;
如果返回YES,则继续识别触摸序列.(默认情况下为YES)。
[insertDemoOne gestureRecognizerShouldBegin:demoGesture];
五、- (NSArray *)constraints NS_AVAILABLE_IOS(6_0); 视图布局约束
约束规则如下:
对于有层次关系的两个view之间的约束关系,添加到层次较高的父级view上。
对于两个不同层级view之间的约束关系,添加到他们最近的共同父级view上。
对于两个同层级view之间的约束关系,添加到他们的父级view上。
六、- (void)addConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0); //视图布局上添加一个约束
七、- (void)addConstraints:(NSArray *)constraints NS_AVAILABLE_IOS(6_0); //视图布局上添加多个约束
八、- (void)removeConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0); 移除视图布局上的一个约束
九、- (void)removeConstraints:(NSArray *)constraints NS_AVAILABLE_IOS(6_0); 移除视图布局上的多个约束
十、- (void)updateConstraintsIfNeeded NS_AVAILABLE_IOS(6_0); //调用新的视图布局自动触发,更新视图布局上的约束
十一、- (void)updateConstraints NS_AVAILABLE_IOS(6_0); // 更新自定义视图布局约束
十二、- (BOOL)needsUpdateConstraints NS_AVAILABLE_IOS(6_0); 判断视图布局是否需要更新约束
13、- (void)setNeedsUpdateConstraints NS_AVAILABLE_IOS(6_0); 设置视图布局是否需要更新约束
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *acceptButton = [UIButton buttonWithType:UIButtonTypeCustom];
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(cancelButton,acceptButton);
NSArray *demoConstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"[cancelButton(72)]-12-[acceptButton(50)]" options:0 metrics:nil views:viewsDictionary]; //取消按钮宽72point,accept按钮宽50point,它们之间间距12point
NSLog(@"%@", demoConstraint);
[oneViewDemo updateConstraintsIfNeeded];
[oneViewDemo updateConstraints];
[oneViewDemo needsUpdateConstraints];
[oneViewDemo setNeedsUpdateConstraints];
[oneViewDemo addConstraints: demoConstraint];
[oneViewDemo addConstraint: [demoConstraint objectAtIndex:0]];
[oneViewDemo removeConstraint:[demoConstraint objectAtIndex:1]];
[oneViewDemo removeConstraints:demoConstraint];
标签:
原文地址:http://www.cnblogs.com/liuxiaokun/p/5544864.html