18-UIKit(Core Animation、广播设计模式)

目录:

一、Core Animation

二、广播设计模式

回到顶部

一、Core Animation

    1.  是什么?

        底层的动画框架

    2.  框架对比

        UIKit           UI      UIView              AppKit          NS  NSView       

        (Cocoa Touch = UIKit + Foundation)          (Cocoa = AppKit + Foundation)

        核心:让好看又能动的东西 在手机上和用户可以交互   

        OC级别:

        +   UIControl/UIView子类

        +   UITableView/UICollectionView

        +   UIGestureRecognizer / UIView touch

       

        Core Animation  CA      CALayer

        (Quartz Core)

        核心:让绘制出来的东西,变得更好看,或者动起来

        C级别:

        UIKit OC级别的简化类

        +   UIView transform

        +   UIView animate...

        +   autoresizing

        +   autolayout

       

        Core Graphic    CG      CGContextRef

        (Quartz 2D)

        核心:绘制

        C级别:线、填充颜色、文字、阴影、图像

        UIKit OC级别的简化类

        +   UIColor

        +   UIBezierPath

        +   NSString(UIKit)      

    3.  UIView vs CALayer

        UIKit                   Core Animation

        UIView                  CALayer

                -> view.layer

        addSubview              addSublayer

        frame                   frame

        autoreszing             autoreszing

        transform 2D            transform 3D

        animate                 animate 3D动画 颜色动画

                                增加一个圆角边

                                增加一个阴影

                                粒子效果

                               

    4.  Layer

        1)  设置圆角

        2)  遮罩/蒙板

        3)  CATransform3D

            内部 4x4 矩阵

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.imageView.layer.cornerRadius = 15;// 设置圆角
    self.imageView.layer.masksToBounds = YES;// 遮罩/蒙板
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = - 1.0 / 1000;
    transform = CATransform3DRotate(transform, M_PI_4, 1, 1, 0);//x轴旋转45度,x轴旋转45度   x y z轴
    self.imageView.layer.transform = transform;
}

回到顶部

二、广播设计模式

概念:

0.生活中的广播,电视直播、收音机、商场、微博

1.什么是广播设计模式?一个对象不用知道消息的接收者是谁,就可以给这些需要消息的对象发消息

2.为什么会有这个模式?

    1>有些情况下,发送消息的发送者无法预测接收者的存在和数量

    2>有些情况下,消息的接收者和发送者距离太远

3.核心逻辑,发送者、收听者

    1>收听者,打开收音机、收听广播,调频到和将来发送者频道一致

    2>发送者发送一个广播,只要曾经打开收音机收听当前频道的收听者都能听到广播

    3>收听者关闭广播

4.ios中对广播的实现

NSNotification                    一条通知

NSNotificationCenter     通知中心

步骤:[MX2]

1.收听者打开收音机收听广播

    1>先找到通知中心

NSNotifecationCenter * center = NSNotifecationCenter defaultCenter

    2>注册收听某主题的广播 addObeserver

2.发生者发送广播

    1>找到通知中心

    2>创建通知对象

    3>发送 使用通知中心发送通知对象post

-(void)kaishi{

    // 找到通知中心

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

    // 创建通知对象

    NSNotification *nofication = [NSNotification notificationWithName:@"WWDC" object:nil];

    // 发送 使用通知中心发送通知对象

    [center postNotification:nofication];

}

3.收听者处理收听

    1>实现收听消息,处理逻辑

4.关闭广播,收听者不需要的时候停掉收听(必须要关)

        1>找到通知中心

        2>remove停掉收听

-(id)init{
    self = [super init];
    if (self) {
        // 找到通知中心
        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
        // 注册收听某主题的广播
        [center addObserver:self selector:@selector(jieshou:) name:@"WWDC" object:nil];
    }
    return self;
}

// 处理收听
-(void)jieshou:(id)sender{
    NSLog(@"jieshoudaole");
}

// 停掉收听
-(void)dealloc{
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center removeObserver:self name:@"WWDC" object:nil];
}

5.通知中心发布信息时同时传送数据

// 创建通知对象
NSDictionary *data = @{@"Product": @"iPad Air"};
NSNotification *nofication = [NSNotification notificationWithName:@"WWDC" object:nil userInfo:data];
//收听这接收数据
-(void)jieshou:(NSNotification *)sender{
    NSLog(@"%@",sender.userInfo[@"Product"]);
}

    6.  内部机理

     [G01]

    7.  广播的同时传输数据

        发送广播的时候 数据放在通知对象的userInfo下

        接收广播的时候,第一个参数不是CCTV而是新闻(NSNotification)

        接收的第一个参数就是发送者创建的通知对象

    8.  字符串常量

        .h

        extern NSString * const XXXxxxXxxxxxxxx;

        .m

        NSString * const XXXxxxXxxxxxxxx = @".....";

    9.  效果

        消息接收者的增加

        不会影响到现有消息发送者的代码

        也不会影响到其它现有接收者的代码

       

    10. 打开广播 / 关闭广播 必须必须配对

init                      - dealloc

viewDidLoad        - viewDidUnload / dealloc

viewWillAppear    - viewDidDisappear

viewDidAppear     - viewWillDisappear

 

选中VC在第四个检查器里,默认选中under top bars意思是该VC渗透在top bar的下面,取消则不渗透

原文地址:https://www.cnblogs.com/yangmx/p/3536335.html