Cat Share, must boutique
Material code Address: http://download.csdn.net/detail/u013357243/8585703
Original address: Http://blog.csdn.net/u013357243?viewmode=contents
Look at the picture first
The first step is to complete the diagram of the TableView and cell shelves
Perfect picture
After the keyboard popup settings Picture:
Auto-reply graph:
Rough's shelves TableView and cell creation
Prime Minister TableView in order to learn the convenience of the direct use of Stroyboard dragged, including some learning significance of the picture and so on are directly in the Stroyboard drag settings, if you want to write all the code once can see my previous article, there are all kinds of introduction.
其实我们知道,上半部分就是一个tableView,但是需要我们自己来编写,这里我们的数据来自plist文件,首先建立了两个模型:NYMessageModel还有NYMessageFrameModel其中NYMessageFrameModel有这些属性
@interface nymessageframemodel : nsobject //position of text@property(nonatomic,Assign,ReadOnly)CGRectTEXTF;//Location of time@property(nonatomic,Assign,ReadOnly)CGRectTIMEF;//position of Avatar@property(nonatomic,Assign,ReadOnly)CGRecticonf;//height of each cell@property(nonatomic,Assign,ReadOnly)CGFloatCELLH;//Data Model@property(nonatomic,Strong) Nymessagemodel *message;+ (Nsmutablearray*) Messageframes;@end
The idea here is to have a frame model with a message model,
When we return an array of frame, each frame in it has a message, and we call the Setmseeage method of the frame at the time of the call, which will set the other properties of the frame such as CELLH and so on. In this way, the data in our frame is full, and the return is an array of frame, which can be used directly by others.
The implementation is written in this way, mainly by calling the Messageframe Setmessage Method-Set the data model method, the various frame set.
Keyboard Notification Notification understanding
Notifications include:
Publication of notifications
Monitoring of notifications
Removal of notifications
1, each application has a notification hubs (Nsnotificationcenter) instance that is specifically designed to assist in message communication between different objects.
2, any object can publish a notification (nsnotification) to the notification center, describing what it is doing. Other objects of interest (Observer) can request to receive this notification when a particular notification is published (or when a particular object is posted).
Usage of notifications
?? A complete notification? Typically contains 3 attributes:
- (NSString *)name; // 通知的名称 -(id)object; // 通知发布者(是谁要发布通知) - (NSDictionary *)userInfo; // ?一些额外的信息(通知发布者传递给通知接收者 的信息内容)
? Initialize? A notification (Nsnotification) object
+ (instancetype)notificationWithName:(NSString *)aName object:(id)anObject; + (instancetype)notificationWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo; - (instancetype)initWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo;
The Notification Heart (Nsnotificationcenter) provides the appropriate method to help publish the notification
? - (void)postNotification:(NSNotification *)notification;
? Publish? A notification notification that sets the name of the notification, the notification Publisher, additional information, and so on in the notification object
? - (void)postNotificationName:(NSString *)aName object: (id)anObject;
? Published? A notification named Aname, AnObject as the publisher of this notification, auserinfo for additional information
? - (void)postNotificationName:(NSString *)aName object:(id)anObjectuserInfo:(NSDictionary *)aUserInfo;
Registering a notification listener
Notice in the Heart (Nsnotificationcenter) provides a method to register? A listener for monitoring notifications (Observer)
? -(void) Addobserver: (ID) Observer selector: (SEL) aselector name:
(NSString *) AName object: (ID) anobject;
? Observer: Listener, who wants to receive this notification
? Aselector: After receiving the notification, the callback listener of this method, and the notification object as a parameter to pass into
? AName: Name of the notification. If it's nil, then? Regardless of the name of the notification, the listener can receive this notification? AnObject: Notifies the publisher. If both AnObject and Aname are nil, the listener receives all notifications
Registering a notification listener
? -(id)addObserverForName:(NSString*)nameobject:(id)obj queue:(NSOperationQueue *)queue usingBlock:(void (^) (NSNotification *note))block;
? Name: Names of notifications
? Obj: Notifies the publisher
? Block: When a corresponding notification is received, the block is called back
? Queue: Determines which operation queue The block is in, and if nil is passed, the default is to synchronize the line in the current Operation queue.
Unregister Notification Listener
? Notice? The heart does not retain (retain) listener object, in the notification, the object registered by the heart must be unregistered before the object is released. Otherwise, when the notification appears again, the heart will still send a message to the listener. Because the corresponding listener object has been freed, it may cause the crash
? The heart of the notification provides the appropriate way to unregister the listener
- (void)removeObserver:(id)observer; - (void)removeObserver:(id)observer name:(NSString *)aName object:(id)anObject;
?. Unregister before the listener is destroyed (e.g. add the following code to the listener):
- (void)dealloc {//[super dealloc]; ?非ARC中需要调?用此句 [[NSNotificationCenter defaultCenter] removeObserver:self];}
Uidevice Notice
The Uidevice class provides a single-grain object that represents the device through which you can obtain information about some device, such as battery level (batterylevel), battery status (batterystate), type of device (model, ipod, IPhone, etc.), device systems (systemversion)
This single-grain object can be obtained by [Uidevice Currentdevice]
Uidevice objects will be published continuously? Some notifications, the following are the name constants of the notifications that are published by the Uidevice object:
UIDeviceOrientationDidChangeNotification// 设备旋转UIDeviceBatteryStateDidChangeNotification// 电池状态改变// 电池电量改变UIDeviceProximityStateDidChangeNotification// 近距离传感器(?比如设备贴 近了使?用者的脸部)
Keyboard notifications
? Do we often need to do this when the keyboard pops up or hides? Some specific operations, so you need to listen to the state of the keyboard
? When the keyboard state changes, the system sends out some specific notifications
// 键盘即将显?示// 键盘显?示完毕// 键盘即将隐藏// 键盘隐藏完毕// 键盘的位置尺?寸即将发?生改变 // 键盘的位置尺?寸改变完毕
Selection of notifications and proxies
? Common
? Lee? The communication between objects can be accomplished by both notification and proxy (? A object that tells D the object what happened, the A object passes the data to the D object)
? Different points
? Agent:? One relationship (one object can only tell the other 1 objects what happened)
? Notification: A Many-to-many relationship (an object can tell n objects what's going on, 1 objects know what happens when n objects are sent?)
QQ keyboard pop-up or hidden
First listen to the Notification Center listening Keyboardchange
The principle of application is that if the keyboard changes, notify us of the @selector method.
//监听通知中心 监听keyboardChange [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
Keyboard Popup
-(void) Keyboarddidchangeframe: (nsnotification*) noti{//Change the background color of window Self. View. Window. BackgroundColor= Self. TableView. BackgroundColor;//Keyboard exit frame CGRectframe = [Noti. UserInfo[Uikeyboardframeenduserinfokey] Cgrectvalue];//Keyboard real-time y CGFloatKeyy = Frame. Origin. Y;//height of screen CGFloatScreenh = [[UIScreen mainscreen] bounds]. Size. Height;//Animation time CGFloatKeyduration = [Noti. UserInfo[Uikeyboardanimationdurationuserinfokey] floatvalue];//Perform animations[UIViewAnimatewithduration:keyduration animations:^{ Self. View. Transform= Cgaffinetransformmaketranslation (0, keyy-screenh); }];}
Keyboard Hide
End Edit Event when TableView scrolls (exit keyboard)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ [self.view endEditing:YES];}
Set the left margin of the input box
Inputview is the following input box ...
//设置输入框的左边距 self.inputView.leftView = [[UIView alloc]initWithFrame:CGRectMake(0080)]; //设置一直显示 self.inputView.leftViewMode = UITextFieldViewModeAlways;
(material source) Cat learn iOS (18) UI QQ Chat Layout _ keyboard notification Implementation Auto Popup Hide _ Auto Reply