拖动雪花视图实例学习
【实例学习】
在实践Pdf版书中P49的例子中,继续学习:
NSSet类
NSSet declares the programmatic interface for static sets of distinct objects. You establish a static set’s entries when it’s created, and thereafter the entries can’t be modified.
此类声明一个可编程接口用于不同对象的静态集合。你可在创建的时候建立静态集合的入口,此后这个接口不能再被修改。
方法:
count
allObjects
anyObject
containsObject
member
浏览了下资料上的所有方案,认为此类和常规的集合类Set是同一类型,尽管部分函数不一致。
在此例代码中,用了anyObject来返回一个对象,对象类型id=UITouch
UIView类
属性
userInteractionEnabled
A Boolean value that determines whether user events are ignored and removed from the event queue.(此布尔值决定是否将用户事件从事件队列中忽略或移出)
@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled
Discussion
When set to NO, user events—such as touch and keyboard—intended for the view are ignored and removed from the event queue. When set to YES, events are delivered to the view normally. The default value is YES.
Note: Some UIKit subclasses override this property and return a different default value.(注意:一些UIKit子类重载了此属性返回了不同的默认值)。 See the documentation for any class you use to determine if it returns a different value for this property.
方法
bringSubviewToFront,用于把子视图放在前端
sendSubviewToBack,用于把子视图放在后端
UITouch类
定义手指在iPhone屏幕上移动的方式。
调用标准的开始、移动和结束处理程序时会发送触摸;还可以查询用户事件来返回触摸,通过touchesForView和touchesForWindow来影响特定的视图。
方法
locationInView:Returns the current location of the receiver in the coordinate system of the given view.
UIImageView类
继承UIView
属性
image
例子中使用的是:[dragger setImage:[UIImage imageNamed:whichFlower]];
也可以这么使用:dragger.image = [UIImage imageNamed:whichFlower];
UIResponder类
The UIResponder class defines an interface for objects that respond to and handle events.
此类为对象定义接口,用于响应和处理事件。
触摸常用接口:
Responding to Touch Events
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
接口参数类型:NSSet和UIEvent
备注:在查询方法的时候,总会忘了setXXXXXX这个方法实际对应是XXXXXX的属性
XCode工具智能些,至少会给出一个声明,可以一目了然的看出方法的来源
例子代码有这么一句:
NSString *whichFlower = [[NSArray arrayWithObjects:@"blueFlower.png", @"pinkFlower.png", @"orangeFlower.png", nil] objectAtIndex:(random() % 3)];
在实践Pdf版书中P49的例子中,继续学习:
NSSet类
NSSet declares the programmatic interface for static sets of distinct objects. You establish a static set’s entries when it’s created, and thereafter the entries can’t be modified.
此类声明一个可编程接口用于不同对象的静态集合。你可在创建的时候建立静态集合的入口,此后这个接口不能再被修改。
方法:
count
allObjects
anyObject
containsObject
member
浏览了下资料上的所有方案,认为此类和常规的集合类Set是同一类型,尽管部分函数不一致。
在此例代码中,用了anyObject来返回一个对象,对象类型id=UITouch
UIView类
属性
userInteractionEnabled
A Boolean value that determines whether user events are ignored and removed from the event queue.(此布尔值决定是否将用户事件从事件队列中忽略或移出)
@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled
Discussion
When set to NO, user events—such as touch and keyboard—intended for the view are ignored and removed from the event queue. When set to YES, events are delivered to the view normally. The default value is YES.
Note: Some UIKit subclasses override this property and return a different default value.(注意:一些UIKit子类重载了此属性返回了不同的默认值)。 See the documentation for any class you use to determine if it returns a different value for this property.
方法
bringSubviewToFront,用于把子视图放在前端
sendSubviewToBack,用于把子视图放在后端
UITouch类
定义手指在iPhone屏幕上移动的方式。
调用标准的开始、移动和结束处理程序时会发送触摸;还可以查询用户事件来返回触摸,通过touchesForView和touchesForWindow来影响特定的视图。
方法
locationInView:Returns the current location of the receiver in the coordinate system of the given view.
UIImageView类
继承UIView
属性
image
例子中使用的是:[dragger setImage:[UIImage imageNamed:whichFlower]];
也可以这么使用:dragger.image = [UIImage imageNamed:whichFlower];
UIResponder类
The UIResponder class defines an interface for objects that respond to and handle events.
此类为对象定义接口,用于响应和处理事件。
触摸常用接口:
Responding to Touch Events
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
接口参数类型:NSSet和UIEvent
备注:在查询方法的时候,总会忘了setXXXXXX这个方法实际对应是XXXXXX的属性
XCode工具智能些,至少会给出一个声明,可以一目了然的看出方法的来源
例子代码有这么一句:
NSString *whichFlower = [[NSArray arrayWithObjects:@"blueFlower.png", @"pinkFlower.png", @"orangeFlower.png", nil] objectAtIndex:(random() % 3)];
无论生活、还是技术,一切都不断的学习和更新~~~努力~