ios 控件   UIKit.framework

1.  IOS 认识

  1.info.plist:
     Bundle name:  应用名称
     Bundle Identifirer:  应用唯一标识

// 获取 Info.plist 路径
   NSString* filepath=  [[NSBundle mainBundle] pathForResource:@"Info.plist" ofType:nil];
   // 获取配置文件,保存字典中
    NSDictionary* dict= [NSDictionary dictionaryWithContentsOfFile:filepath];
    // 获取当前版本号
    NSLog(@"dict=%@",dict[@"CFBundleShortVersionString

 2. UiApplication的常用属性: 
    设置应用程序图标
    设置状态栏
    打开网页、发短信、发邮件、打电话

3. UIApllication的 delegate 代理:
   1.  应用程序生命周期
   2.  系统事件
   3.  内存警告
https://www.jianshu.com/p/5b7c2e72a5f6

 2.  IOS 基础控件   UIKit.framework

UiKit坐标系:  [选中控件,属性面板第6个]
1. 控件坐标是相对坐标: 现对于父控件的位置,每一个子控件
2. 左上角是原点 

1. 按下 option拖,复制控件
2. xcode11 拖线找不到控制器: https://blog.csdn.net/qq_20255275/article/details/102784747   
Touch up inside 事件,点击事件,拖入头文件中
属性连线 :Referencing Outlets,拖入匿名分类中即可
3.删除方法的时候,把连线的方法也删除


   UIKit.frework  
1. 按下 option拖,复制控件
2. xcode11 拖线找不到控制器: https://blog.csdn.net/qq_20255275/article/details/102784747   
Touch up inside 事件,点击事件,拖入头文件中
属性连线 :Referencing Outlets,拖入匿名分类中即可
3.删除方法的时候,把连线的方法也删除


UiKit坐标系:  [选中控件,属性面板第6个]
1. 控件坐标是相对坐标: 现对于父控件的位置,每一个子控件
2. 左上角是原点 

1. 案例1   求和, 如何拖控件、点击方法
2. 案例2 设置随机颜色
3. 动态生成View
4. 案例4:动画
5. 案例5: 按钮创建
6. 基本属性控制api : 扩大、旋转、缩放、平移
7 : 删除指定tag  控件 、  删除父控件下所有子控件

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

// 方法拖入头文件即可,点击事件
- (IBAction)jisuang:(id)sender;


@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()
// 私有属性 1
@property (weak, nonatomic) IBOutlet UITextField *text1;
// 私有属性 2
@property (weak, nonatomic) IBOutlet UITextField *text2;
// 求和
@property (weak, nonatomic) IBOutlet UILabel *sumText;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}


- (IBAction)jisuang:(UIButton* )sender {
    NSDate* now = [NSDate new];
    NSDateFormatter* nsformater= [NSDateFormatter new];
        nsformater.dateFormat=@"yyyy-MM-dd HH:mm:ss";
    NSString* str= [nsformater stringFromDate:now];
    // 获取控件1  控件2的 文本值
    int text1= [self.text1.text intValue];
    int text2= [self.text2.text intValue];
    
    int sum =text1 + text2;
    // 1. 案例1   求和
    [self.sumText setText:[NSString stringWithFormat:@"%d",sum]];
    
    //  取消控制器View的编辑状态
    //  隐藏键盘
    [self.view endEditing:YES];
    
    // 2. 案例2 设置随机颜色
    // 获取 父元素
    UIView* father= sender.superview;
    // 生成随机数
    float randomR= arc4random_uniform(255)/255.0;
    float randomG= arc4random_uniform(255)/255.0;
    float randomB= arc4random_uniform(255)/255.0;
    // 随机颜色,这里参数是[0,1]
    UIColor* randomColor= [UIColor colorWithRed:randomR green:randomG blue:randomB alpha:1];

    father.backgroundColor= randomColor;
    NSLog(@"hel---------%@",str);
    
    // 3. 动态生成View
    UIView* addView= [UIView new];
    // 设置控件位置以及尺寸
    addView.frame= CGRectMake(0, 0, 30, 30);
    addView.backgroundColor=[UIColor redColor];
    // 添加控件
    [father addSubview:addView];
    
    // 案例4:动画
    // 不能直接修改frame的 值
  //  addView.frame.origin.x=230;
    CGRect oldFrame = addView.frame;
    oldFrame.origin.x= 100;
    oldFrame.origin.y= 100;
    // 动画方式1: 头尾式动画, ios13 已经废弃
//    [UIView beginAnimations:nil context:nil];
//    [UIView setAnimationDuration:10];
//    [UIView setAnimationDelay:2];
//    // 赋值回去
//    addView.frame=oldFrame;
//    [UIView commitAnimations];
    
    // 动画方式2:
    [UIView animateWithDuration:3 animations:^{
        // 动画要改变的值
        addView.frame= oldFrame;
    }];
    
    
    // 案例5: 按钮创建
    UIButton* button= [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(30, 30, 50, 50);
    /**
    UIButton控件状态:
      default
      Highighted: 点击
      Selected: 选择
      Disabled: 禁用状态
     */
    // 枚举  提示按下 esc 键
    [button setTitle:@"点我" forState:UIControlStateNormal];
    UIImage* image= [UIImage imageNamed:@"btn_01.png"];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    
    [father addSubview:button];
    // 使用代码添加点击事件
    [button addTarget:self action:@selector(doSomeThings) forControlEvents:UIControlEventTouchUpInside
     ];
    
    
}

// 案例6: 基本属性控制api   扩大、旋转、缩放、平移
- (IBAction)startAnimation:(id)sender {
      
//    CGRect oldFrame = self.donghuaImage.frame;
//    // 中心点扩大
//    oldFrame.size.height= oldFrame.size.height+20;
//    oldFrame.size.width = oldFrame.size.height+20;
//    oldFrame.origin.x = oldFrame.origin.x -10 ;
//    oldFrame.origin.y = oldFrame.origin.y -10 ;
    // self.donghuaImage.frame= oldFrame;
    
    
    //使用 transfrom 属性来设置按钮 旋转 , 旋转必须是弧度
  //  self.donghuaImage.transform= CGAffineTransformMakeRotation(M_PI_4);
    // 累加 旋转 , 在原始值的基础上累加 self.donghuaImage.transform
    self.donghuaImage.transform= CGAffineTransformRotate(self.donghuaImage.transform, M_PI_4);
    
    
 //   CGAffineTransformMake(<#CGFloat a#>, <#CGFloat b#>, <#CGFloat c#>, <#CGFloat d#>, <#CGFloat tx#>, <#CGFloat ty#>)   // 参数最多,定制最强
  //  CGAffineTransformMakeRotation(<#CGFloat angle#>)  // 旋转
  //  CGAffineTransformMakeScale(CGFloat sx, <#CGFloat sy#>)   缩放
  //   CGAffineTransformTranslate(<#CGAffineTransform t#>, <#CGFloat tx#>, <#CGFloat ty#>)  // 平移
}


//案例7 : 删除指定tag  控件 、  删除父控件下所有子控件
- (IBAction)clickBtn:(id)sender {
    // 删除指定tag  控件
    UIButton* btn10= [self.whiteView viewWithTag:10];
  //  [btn10 removeFromSuperview];
    
    // 删除所有子控件
    for (UIView* view in self.whiteView.subviews) {
//        if( [view isKindOfClass: [UIButton class]]){
//            continue;
//        }
        [view removeFromSuperview];
    }
}

-(void)doSomeThings{
    NSLog(@"点击按钮");
}
@end

效果:

3.   帧动画

UIimage imageName 与 imageWithContentsOfFile 区别,播放帧动画



#import "HomeController.h"

@interface HomeController ()
@property (weak, nonatomic) IBOutlet UIImageView *animation;

@end

@implementation HomeController

/**
 播放帧动画:
 1.  UIimage imageName:图片名,  这种方式加载图片  会在内存中常驻 ,一般用于背景图片,小箭头  icon等等,  第一次加载以后,后面使用直接读取缓存中
    对于需要释放的图片  使用 imageWithContentsOfFile  加载图片,只有当没有任何一种对象对他进行 强引用的时候,才会释放
  
 2.   项目中,  如果是帧动画,需要播放完以后释放,  使用  imageWithContentsOfFile
 不做缓存
 
 */


// 帧动画  播放方式1:
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
//    if([self.animation isAnimating]){
//        return;
//    };
//
//    NSMutableArray * arry=[NSMutableArray array];
//    for (int i=0; i< 26 ; i++) {
//     // 1. 拼接图片名字
//        NSString* imageNameStr= [NSString stringWithFormat:@"angry_%02d",i];
//
//        NSLog(@"lujing==%@",imageNameStr);
//
//        // 2. 加载图片
//       UIImage* image= [UIImage imageNamed:imageNameStr];
//
//       [arry addObject:image];
//    }
//
//    // 把加载好的图片 设置给UIIMageView
//    self.animation.animationImages= arry;
//           // 开始播放动画
//
//    // 设置播放动画的细节
//    self.animation.animationDuration=2;
//    self.animation.animationRepeatCount=2;
//
//           [self.animation startAnimating];
    
}


// 帧动画   播放方式 2
- (IBAction)clickAnimation:(id)sender {
    
    if([self.animation isAnimating]){
        return;
    };
    
    NSMutableArray * arry=[NSMutableArray array];
       for (int i=1 ; i<40 ; i++) {
        // 1. 拼接图片名字
           NSBundle* mainBund=[NSBundle mainBundle];
           // 获取 项目 下 沙盒路径
 // 可以把图片拷贝到项目根目录下,项目根目录下可以有文件夹,查看沙盒的时候文件夹会去掉
           NSString* imageNameStr= [NSString stringWithFormat:@"gun%03d.png",i];
           NSString* imagePath =[ mainBund pathForResource:imageNameStr ofType: nil];
           
           NSLog(@"lujing==%@",imagePath);
           
           // 2. 加载图片a
    UIImage* image= [UIImage imageWithContentsOfFile:imagePath];
           [arry addObject:image];
       }
    
    self.animation.animationImages= arry;
    
    self.animation.animationDuration=40*0.1;
      self.animation.animationRepeatCount=2;
      
             [self.animation startAnimating];
      // 播放完成以后释放 引用,才可以释放内存
    [self performSelector:@selector(cleanImage) withObject:nil afterDelay:40*0.1*2];
    
    
}

// 清除动画引用 
-(void)cleanImage{
    self.animation.animationImages=nil;
}

@end

4.  九宫格实现

4.1.  通过代码方式实现九宫格

#import "Home17Controller.h"
#import "ItemLogin.h"
#import "AppModel.h"

@interface Home17Controller ()

//  都声明为可变的,否则无法add 添加元素
@property(nonatomic,strong) NSMutableArray* dataArray;

@end


@implementation Home17Controller

// 1. 重写get 方法从网络获取数据,懒加载避免多次调用
-(NSMutableArray*)dataArray{
    if(_dataArray == nil){
//       NSString* path= [[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil];
//       _dataArray= [NSMutableArray arrayWithContentsOfFile:path];
        _dataArray= [NSMutableArray new];
        for (int i=0; i<12; i++) {
            AppModel* appModel= [AppModel new];
            appModel.lableName=[NSString stringWithFormat:@"xiao%d",i];
            [_dataArray addObject:appModel];
        }
       
    }
    return _dataArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    CGFloat yellowViewWidth= 80;
    CGFloat yellowViewHeight= 90;
    
    CGFloat kColumn =3;
    
    CGFloat margin= (self.view.frame.size.width - kColumn* yellowViewWidth)/ (kColumn+1);
    
    for (int j=0; j< 4; j++) {  // 确定行
        for (int i=0; i< kColumn; i++) {  // 确定列
            // 每一个View的 x 、y 坐标
            CGFloat yellowViewX= (i+1) * margin + i*yellowViewWidth;
            CGFloat yellowViewY= (j+1) * margin + j*yellowViewHeight;
       // 外部Item对应的View
               UIView* itemView= [[UIView alloc] initWithFrame:CGRectMake(yellowViewX, yellowViewY, yellowViewWidth, yellowViewHeight)];
            
            NSLog(@"%f,%f",yellowViewX,yellowViewY);
            itemView.backgroundColor=[UIColor blueColor];

            [self.view addSubview:  itemView];

            CGFloat imageWidth= 45;
            CGFloat topY = 10;
            // 1. 添加ImageView
            CGFloat imageViewX= (yellowViewWidth- imageWidth )/2;
            UIImageView* iconImage = [[UIImageView alloc] initWithFrame:CGRectMake(imageViewX, topY, imageWidth, imageWidth)];
            [iconImage setBackgroundColor:[UIColor redColor]];

            [itemView addSubview:iconImage];

            // 2.添加lable, 获取y 坐标
            CGFloat labelY = CGRectGetMaxY(iconImage.frame);

            UILabel* label= [[UILabel alloc] initWithFrame:CGRectMake(0, labelY, itemView.frame.size.width, 15)];

            // label.backgroundColor=[UIColor blackColor];

            label.textAlignment= NSTextAlignmentCenter;
            label.text=[NSString stringWithFormat:@"a%d",i];

            // 加粗
         //   label.font= [UIFont systemFontOfSize:20];
            label.font= [UIFont boldSystemFontOfSize:20];
            [itemView addSubview:label];

            //3.  添加button
            CGFloat buttonX= ( itemView.frame.size.width-imageWidth)/2;
            CGFloat buttonY= CGRectGetMaxY(label.frame);
            UIButton* downloadButton= [[UIButton alloc] initWithFrame:CGRectMake(buttonX, buttonY, imageWidth, 20)];

            // 默认状态
            [downloadButton setBackgroundImage:[UIImage imageNamed:@"buttongreen.png"]
                                      forState:UIControlStateNormal];

            // 点击按下状态
              [downloadButton setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted.png"] forState:UIControlStateHighlighted];

            [downloadButton setTitle:@"下载" forState:UIControlStateNormal];
            [itemView addSubview:downloadButton];
           
        }
    }
}


@end

4.2.  通过xib 的方式 实现

#import "Home17Controller.h"
#import "ItemLogin.h"
#import "AppModel.h"

@interface Home17Controller ()

//  都声明为可变的,否则无法add 添加元素
@property(nonatomic,strong) NSMutableArray* dataArray;
@end


@implementation Home17Controller

// 1. 重写get 方法从网络获取数据,懒加载避免多次调用
-(NSMutableArray*)dataArray{
    if(_dataArray == nil){
//       NSString* path= [[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil];
//       _dataArray= [NSMutableArray arrayWithContentsOfFile:path];
        _dataArray= [NSMutableArray new];
        for (int i=0; i<12; i++) {
            AppModel* appModel= [AppModel new];
            appModel.lableName=[NSString stringWithFormat:@"xiao%d",i];
            [_dataArray addObject:appModel];
        }
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    CGFloat yellowViewWidth= 80;
    CGFloat yellowViewHeight= 90;
    
    CGFloat kColumn =3;
    
    CGFloat margin= (self.view.frame.size.width - kColumn* yellowViewWidth)/ (kColumn+1);
    
    for (int j=0; j< 4; j++) {  // 确定行
        for (int i=0; i< kColumn; i++) {  // 确定列
            // 每一个View的 x 、y 坐标
            CGFloat yellowViewX= (i+1) * margin + i*yellowViewWidth;
            CGFloat yellowViewY= (j+1) * margin + j*yellowViewHeight;
       
            // 一个xib中可能有多个UIView,返回UIView
                   // 安装以后最终应用程序以nib结尾,所以loadNibName
            NSArray* itemXib= [[NSBundle mainBundle] loadNibNamed:@"itemLogin" owner:nil options:nil];
                    ItemLogin* xibView1= [itemXib firstObject];
                    int index= j* i + i;
                    NSLog(@"array:%@",self.dataArray);
                                          
                  //  设置model
                    xibView1.appModel = self.dataArray[index];
        
                    NSLog(@"---%@",xibView1);
                    [xibView1 setFrame:CGRectMake(yellowViewX, yellowViewY, yellowViewWidth,yellowViewHeight)];
                    [self.view addSubview:xibView1];
           
        }
    }
}
@end

Xib 布局实现

设置freedom,不是默认的viewctroller视图

 

xib 对应 ItemLogin.h 设置属性,用于设置xib 控件数据


#import <UIKit/UIKit.h>

@class AppModel;

NS_ASSUME_NONNULL_BEGIN

@interface ItemLogin : UIView

@property(nonatomic,copy) AppModel* appModel;

@end

NS_ASSUME_NONNULL_END

ItemLogin.m

#import "ItemLogin.h"
#import "AppModel.h"

@interface   ItemLogin()
@property (weak, nonatomic) IBOutlet UIImageView *iconImgeView;

@property (weak, nonatomic) IBOutlet UILabel *lableText;

@end


@implementation ItemLogin

-(void)setAppModel:(AppModel *)appModel{
    
    _appModel= appModel;
    
    _lableText.text= _appModel.lableName;
    
};

@end

5.  对话框的使用

 // 对话框显示
- (IBAction)clickMe:(id)sender {
    //  UIAlertControllerStyleAlert: 在屏幕中间显示
   // UIAlertControllerStyleActionSheet: 从下面往上面显示
    //  1. 实例化UIAlertController
    UIAlertController*  alertController= [UIAlertController alertControllerWithTitle:@"标题" message:@"内容" preferredStyle:UIAlertControllerStyleAlert];
   //2. 添加按钮
    UIAlertAction* cancleAction= [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertController addAction:cancleAction];
    //UIAlertActionStyleDefault
    // UIAlertActionStyleDestructive : 按钮是红色的
    UIAlertAction* sureAction= [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertController addAction:sureAction];
    
    //3.  显示
    [self presentViewController:alertController animated:YES completion:^{
        
    }];
}

6.  代理使用

FouterView.h: 

#import <UIKit/UIKit.h>
@class FooterView;
 // 1.定义协议
@protocol FooterViewDelegate <NSObject>
- (void)footerView:(FooterView *)footerView;
@end


@interface FooterView : UIView
  // 2. 代理属性
@property (nonatomic, weak) id<FooterViewDelegate> delegate;

@end

 FouterView.m:  

- (IBAction)didClickLoadButton:(id)sender {
// 3. 通知代理(控制器), 插入新的数据
    if ([self.delegate respondsToSelector:@selector(footerView:)]) {
        [self.delegate footerView:self];
    }
}

ViewController.m

@interface ViewController ()<UITableViewDataSource,FooterViewDelegate>
- (void)viewDidLoad {

  FooterView *footerView = [[[NSBundle mainBundle] loadNibNamed:@"FooterView" owner:nil options:nil] lastObject];
   // 4. 设置控制器成为footterView的代理
    footerView.delegate = self;
}

// 5. 代理回调,实现代理接口
 - (void)footerView:(FooterView *)footerView {

 }
@end 

 7.   通知

 Objective-c 通知原理:             发布通知                                          

                                                                   观察者1 
  被观察者   ----------->通知中心    ---- > 观察者2
                                                                   观察者3


   1. 观察者 注册通知到通知中心 
 2. 被观察者 发布通知通过 通知 中心
 3. 当 观察者 对象 被销毁的 时候,
一定要从 通知中心 把他 给移除掉

案例:通知下载
DownLoadManager.h        DownLoadManager.m

#import <Foundation/Foundation.h>


// 观察者

@interface DownLoadManager : NSObject

@property(nonatomic,copy) NSString* name;


-(void) receiveNotifiction :(NSNotification*) noti;

@end

 

#import "DownLoadManager.h"

@implementation DownLoadManager


-(void) receiveNotifiction :(NSNotification*) noti{
    
    NSLog(@"%@",noti);
    
    NSDictionary* dict= noti.userInfo;
    
    DownLoadManager* down= dict[@"manager"];
    
    NSLog(@"名称:%@,下载进度%@", down.name, dict[@"degree"]);
    
    
}


// 3. 从 一旦 观察者挂了,从通知中心 移除
-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}

@end

DownLoadDetail.h   DownLoadDetail.m

#import <Foundation/Foundation.h>


 // 观察者
@interface DownLoadDetail : NSObject

@property(nonatomic,copy) NSString* name;

-(void) receiveNotifiction :(NSNotification*) noti;

@end


#import "DownLoadDetail.h"

@implementation DownLoadDetail


-(void) receiveNotifiction :(NSNotification*) noti{
    NSLog(@"%@",noti);
    
    NSDictionary* dict= noti.userInfo;
    
    DownLoadDetail* down= dict[@"manager"];
    
    NSLog(@"名称:%@,下载进度%@", down.name, dict[@"degree"]);  
}
// 3. 从 一旦 观察者挂了,从通知中心 移除
-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}

@end

main.m



#import <Foundation/Foundation.h>

#import "DownLoadItem.h"
#import "DownLoadManager.h"
#import "DownLoadDetail.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        //1.  观察者注册  给被观察者 , 观察者 重写通知方法
        
        /*
         addObserver : 观察者
         selector : 接收到通知的时候,观察者调用监听者的方法
         name :  被观察者通知的名称, 如果系统通知,系统已经定义
         object :被观察者实例对象,可以传递为 nil
         
         原理:通知 中心发送通知,被被观察者 根据name 接收
         如果 name 为nil ,那么 所有的通知都可以 接收
         */
        
        DownLoadManager* downloadManager= [[ DownLoadManager alloc] init];
              downloadManager.name=@"我是观察者,下载列表界面";
        [[ NSNotificationCenter defaultCenter] addObserver:downloadManager selector:@selector(receiveNotifiction:) name:@"downloadManager" object:downloadManager];
        
        // 下载详情界面
        DownLoadDetail* downloadDetail= [[ DownLoadDetail alloc] init];
              downloadDetail.name=@"我是观察者,下载详情界面";
        [[ NSNotificationCenter defaultCenter] addObserver:downloadDetail selector:@selector(receiveNotifiction:) name:@"downloadDetail" object:downloadDetail];
        
        // 2.  被观察者 发布通知,根据name 发送,name 唯一标识
        /**
        postNotificationNam : 被观察者名称,必须和注册的时候名字保持一致
         object : 消息的发布者
         userInfo : 自定义的消息
         */
        
        [[ NSNotificationCenter defaultCenter]  postNotificationName:@"downloadManager" object:downloadManager userInfo:@{@"manager":downloadManager,@"degree":@(50)}];
        
       [[ NSNotificationCenter defaultCenter]  postNotificationName:@"downloadDetail" object:downloadDetail userInfo:@{@"manager":downloadDetail,@"degree":@(150)}];
        
      
    
    }
    return 0;
}

输出结果: 

2020-05-31 19:55:54.736225+0800 ObjectiveC通知[6865:328909] NSConcreteNotification 0x100613360 {name = downloadManager; object = <DownLoadManager: 0x100617210>; userInfo = {
    degree = 50;
    manager = "<DownLoadManager: 0x100617210>";
}}
2020-05-31 19:55:54.736605+0800 ObjectiveC通知[6865:328909] 名称:我是观察者,下载列表界面,下载进度50
2020-05-31 19:55:54.737077+0800 ObjectiveC通知[6865:328909] NSConcreteNotification 0x10051d200 {name = downloadDetail; object = <DownLoadDetail: 0x1006177a0>; userInfo = {
    degree = 150;
    manager = "<DownLoadDetail: 0x1006177a0>";
}}
2020-05-31 19:55:54.737166+0800 ObjectiveC通知[6865:328909] 名称:我是观察者,下载详情界面,下载进度150
Program ended with exit code: 0


 实际应用: 
     键盘监听: 被观察者,系统定义


#import "NotificationController.h"

@interface NotificationController ()

@end

@implementation NotificationController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillApper:) name:UIKeyboardWillShowNotification object:nil];
    
}
//UIKeyboardWillShowNotification  键盘即将出现通知
-(void)keyboardWillApper:(NSNotification* ) noti{
    NSLog(@"%@",noti);
 /***
输出结果 :
  NSConcreteNotification 0x6000030b7b40 {name = UIKeyboardWillShowNotification; userInfo = {
      UIKeyboardAnimationCurveUserInfoKey = 7;                 动画频率
      UIKeyboardAnimationDurationUserInfoKey = "0.25";     动画时间
      UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {414, 271}}";     键盘高度
      UIKeyboardCenterBeginUserInfoKey = "NSPoint: {207, 871.5}";
      UIKeyboardCenterEndUserInfoKey = "NSPoint: {207, 600.5}";
      UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 736}, {414, 271}}";  没有弹出时候的位置
      UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 465}, {414, 271}}";  弹出以后位置
      UIKeyboardIsLocalUserInfoKey = 1;
  }}
  */
}


@end

  监听文本内容变化: 

- (void)viewDidLoad {
    [super viewDidLoad];
// 监听文本变化通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(valueChaged) name:UITextFieldTextDidChangeNotification object:self.textName];
}
 // 文本内容变化了
-(void)valueChaged{
    NSLog(@"%@",self.textName.text);
}
-(void)dealloc{
  // 移除通知
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值