* textfield,delegation,debugger
1.create TextField
CGRect textFieldRect = CGRectMake(40,70,240,30);
UITextField *textField = [[UITextField alloc] initWithFrame:textFieldRect];
textfield.borderStyle = UITextBorderStyleRoundedRect;
2.first responder
UIResponder是UIKit中一个抽象类,是UIView,UIViewController,UIApplication的父类
UIResponder 定义了处理事件的方法。例如摇动手机,触摸按钮等。对应的事件由子类自己去重写该如何处理。
UIWindow有指向UIResponder的指针:firstResponder,当选择一个textfield,该指针指向它。 当一个文本输入框是firstResponder,键盘出现。不是的时候,隐藏。
如果你想让某个视图变成firstResponder,发送becomFirstResponder以及不想要了,发送resignFirstResponder. 用来隐藏键盘
很多视图是不想成为firstResponder,例如UISlider,它可以接受touch事件,但从不是firstResponder
3.自定义键盘
属性是配置在textField上。
textField.returnKeyType = UIRetureKeyDone; return 变成done
autocapitalizationType
none,words,sentences,characters.
autocorrectionType
yes,no
enalesReturnKeyAutomatically
yes,no
keyboardType
ascii,email,number,url
secureTextEntry
enter the password
4.Delegation
设定一个对象的delegate为自己,
textfield.delegate = self;
然后重写一些自己关心的方法。方法会在合适的条件下被调用
5.Protocols
@option的发送之前会检查一次 respondsToSelector:
@require 默认就是,不会检查,直接发送。如果没有重写则crash
内部实现大概:
获取delegate[自己指定],然后判断
-(void) clearButtonTapped
{
//textFieldShouldClear:is an option method
// so we check first
SEL clearSelector = @selector(textFieldShouldClear);
if([self.delegate respondsTpSelector:clearSelector]){
if([self.delegate textFieldShouldClear:self]){
self.text = @"";
}
}
}
在有文件或者实现文件[看你想不想公开]声明实现某个协议
@interface BNRHyponsisViewController() <UITextFieldDelegate>
@end
6.手势特效
像壁纸那样,当你转动设备的时候,壁纸会偏移
UIInterpolatingMotionEffect
7.Using Debugger
黑色字体是自己编写的代码。
灰色是苹果的代码。
你可以设置自动断点,当应用在崩溃前。在断点面板,点击+ 添加 Add Exception Breakpoint...
8.main(), UIApplication
int main(){
@autoreleasepool {
return UIApplicationMain(argc,argv,nil,NSStringFromClass([BNRAppDelegate class]));
}
}
- UIApplicationMain 创建了UIApplication 的实例,也是唯一一个
- UIApplicationMain 还做了: 创建了一个实例作为 UIApplication's delegate
- 每个应用的第一个被添加的时间是 "kick-off"来触发应用发送消息给自己的delegate,这个消息是:
application:didFinishLaunchingWithOptions:
我们重写了这个消息,来创建窗口和视图控制器
1.create TextField
CGRect textFieldRect = CGRectMake(40,70,240,30);
UITextField *textField = [[UITextField alloc] initWithFrame:textFieldRect];
textfield.borderStyle = UITextBorderStyleRoundedRect;
2.first responder
UIResponder是UIKit中一个抽象类,是UIView,UIViewController,UIApplication的父类
UIResponder 定义了处理事件的方法。例如摇动手机,触摸按钮等。对应的事件由子类自己去重写该如何处理。
UIWindow有指向UIResponder的指针:firstResponder,当选择一个textfield,该指针指向它。 当一个文本输入框是firstResponder,键盘出现。不是的时候,隐藏。
如果你想让某个视图变成firstResponder,发送becomFirstResponder以及不想要了,发送resignFirstResponder. 用来隐藏键盘
很多视图是不想成为firstResponder,例如UISlider,它可以接受touch事件,但从不是firstResponder
3.自定义键盘
属性是配置在textField上。
textField.returnKeyType = UIRetureKeyDone; return 变成done
autocapitalizationType
none,words,sentences,characters.
autocorrectionType
yes,no
enalesReturnKeyAutomatically
yes,no
keyboardType
ascii,email,number,url
secureTextEntry
enter the password
4.Delegation
设定一个对象的delegate为自己,
textfield.delegate = self;
然后重写一些自己关心的方法。方法会在合适的条件下被调用
5.Protocols
@option的发送之前会检查一次 respondsToSelector:
@require 默认就是,不会检查,直接发送。如果没有重写则crash
内部实现大概:
获取delegate[自己指定],然后判断
-(void) clearButtonTapped
{
//textFieldShouldClear:is an option method
// so we check first
SEL clearSelector = @selector(textFieldShouldClear);
if([self.delegate respondsTpSelector:clearSelector]){
if([self.delegate textFieldShouldClear:self]){
self.text = @"";
}
}
}
在有文件或者实现文件[看你想不想公开]声明实现某个协议
@interface BNRHyponsisViewController() <UITextFieldDelegate>
@end
6.手势特效
像壁纸那样,当你转动设备的时候,壁纸会偏移
UIInterpolatingMotionEffect
7.Using Debugger
黑色字体是自己编写的代码。
灰色是苹果的代码。
你可以设置自动断点,当应用在崩溃前。在断点面板,点击+ 添加 Add Exception Breakpoint...
8.main(), UIApplication
int main(){
@autoreleasepool {
return UIApplicationMain(argc,argv,nil,NSStringFromClass([BNRAppDelegate class]));
}
}
- UIApplicationMain 创建了UIApplication 的实例,也是唯一一个
- UIApplicationMain 还做了: 创建了一个实例作为 UIApplication's delegate
- 每个应用的第一个被添加的时间是 "kick-off"来触发应用发送消息给自己的delegate,这个消息是:
application:didFinishLaunchingWithOptions:
我们重写了这个消息,来创建窗口和视图控制器