一、学习目标:
记录OC(objective-c)开发以及编程遇到部分的问题。
后续实体机调测、上架App Store可参阅iOS使用Xcode调测及上架-CSDN博客。
OC是iOS开发常用语言之一,常用的编程框架是MVC(M即Model-数据模型,V即View-视图界面,C即Controller-管理控制)。
二、常见控件
由于每种控件的属性和方法太多,本章节只介绍开发过程中常用的部分。
很多控件之间存在继承关系,继承者包含父类的属性及方法,本章后续不再进行赘述,仅标识继承的父类。
1.UIView
作用:最基础的视图类,用于布局展示、响应事件。 属性:
@property(nonatomic) CGRect frame; //设置view的位置尺寸,起点相对于父视图控件。如果非恒等变换使用bounds/center。。
@property(nonatomic) CGRect bounds; //设置view的位置尺寸,起点相对于屏幕。 @property(nonatomic) CGPoint center;
//center是view的中心。
@property(nonatomic) NSInteger tag;
//给View设置标签,后续可使用viewWithTag查找到此view。 @property(nonatomic,readonly,strong) CALayer *layer;
//view的层,可以再层上添加边框等操作。
@property(nullable, nonatomic,readonly) UIView *superview;
//view的父视图,通过addSubview方式。 @property(nonatomic,readonly,copy) NSArray<__kindof UIView *> *subviews;
//view的子视图。
@property(nonatomic,getter=isHidden) BOOL hidden;
//设置view是否隐层,默认为NO(不隐藏),若隐藏view即子控件,请全部设置隐藏。
方法:
- (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;
// 初始化并设置frame。
- (void)removeFromSuperview;
//将view从父视图中移除。
- (void)addSubview:(UIView *)view;
//添加子视图。
- (nullable __kindof UIView *)viewWithTag:(NSInteger)tag;
// 包括自身view递归查找设置为tag的view。
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
// 设置简单动画。
2.UIViewController
作用:视图控制器,处理视图中各个子控件运行的逻辑。把UIView举例为一张静止的图片,那么UIViewController就相当于图片播放器,控制着图片上下移动、前后播放等逻辑。
属性:
@property(null_resettable, nonatomic,strong) UIView *view;
// 如果视图尚未设置,getter首先调用[self loadView]。如果子类重写了setter或getter,则必须调用super。 @property(nullable, nonatomic,copy) NSString *title;
//用于父控制器的本地化标题。
方法:
- (void)viewDidLoad;
// 在视图被加载后调用。运行此函数的时候获取不到superview设置的属性值。 - (void)viewWillAppear:(BOOL)animated;
// 当视图即将可见时调用。 - (void)viewDidAppear:(BOOL)animated;
// 当视图完全过渡到屏幕上时调用。此函数可以接受父view设置的属性值。 - (void)viewWillDisappear:(BOOL)animated;
// 当视图被解除、覆盖或以其他方式隐藏时调用。默认不做任何事。 - (void)viewDidDisappear:(BOOL)animated;
// 在视图被解除、覆盖或以其他方式隐藏后调用。默认不做任何事。
注意:重写以上方法时,在方法内部需要先包含方法原本的实现,以下为列举的实现:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIView *view1 = [[UIView alloc] init]; view1.frame = CGRectMake(100, 100, 100, 100); view1.backgroundColor = [UIColor blueColor]; view1.tag = 0x1; [self.view addSubview:view1]; }
3.UILabel
作用:标签。可以通过设置label显示文字、图片、动画等。继承自UIView。
属性:
@property(nullable, nonatomic,copy) NSString *text;
// 显示的文字,默认为空。 @property(null_resettable, nonatomic,strong) UIFont *font;
// 文字默认为系统字体17号。 @property(null_resettable, nonatomic,strong) UIColor *textColor;
// 文字默认为黑色。 @property(nullable, nonatomic,strong) UIColor *shadowColor;
// 默认没有阴影。 @property(nonatomic) NSTextAlignment textAlignment;
//默认为NSTextAlignmentNatural(在iOS 9之前,默认为NSTextAlignmentLeft)。 @property(nullable, nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0);
//默认为空, 当设置label中的文字采用两种及以上的字体、颜色时是指此属性(如果设置,会忽略以上属性)。 @property(nullable, nonatomic,strong) UIColor *highlightedTextColor;
// 设置label文字的高亮颜色。 @property(nonatomic,getter=isHighlighted) BOOL highlighted;
// 设置label文字为高亮状态。 @property(nonatomic,getter=isEnabled) BOOL enabled;
// 默认为YES。更改标签的绘制方式。 @property(nonatomic) NSInteger numberOfLines;
//设置label显示文字的行数,默认为1行,设置为0时不限制行数。
4.UIButton
作用:标签。button样式可以显示为文字、图片,设置点击方法处理对应事件。继承自UIControl(UIControl继承自UIView)。
属性:
@property(nonatomic,readonly) UIButtonType buttonType;
//button的样式类型。 @property(nullable, nonatomic,readonly,strong) UILabel *titleLabel NS_AVAILABLE_IOS(3_0);
//button的标题label。 @property(nullable, nonatomic,readonly,strong) UIImageView *imageView NS_AVAILABLE_IOS(3_0);
//button的图案。
方法:
- (void)setTitle:(nullable NSString *)title forState:(UIControlState)state;
//设置button的标题,默认为nil。假定标题为单行。
- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
//设置button的响应事件,默认为nil(此方法于UIControl中继承)。
5.UITextField
作用:接受用户输入的文本信息。继承自UIControl(UIControl继承自UIView)等类。
属性:
@property(nullable, nonatomic,copy) NSString *text;
// 文本编辑框中的文字,默认为空。 @property(nullable, nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0);
// 同UILabel。 @property(nullable, nonatomic,strong) UIColor *textColor;
// 文本颜色,默认为黑色。 @property(nullable, nonatomic,strong) UIFont *font;
// 文本字体,默认为系统12号。 @property(nonatomic) NSTextAlignment textAlignment;
// 同UILabel。 @property(nonatomic) UITextBorderStyle borderStyle;
// 默认是UITextBorderStyleNone。如果设置为UITextBorderStyleRoundedRect,自定义背景图像将被忽略。 @property(nonatomic,copy) NSDictionary
// 将属性应用于整个文本范围。未设置的属性与默认值类似。 @property(nullable, nonatomic,copy) NSString *placeholder;
// 文本为空时现实的提示信息,默认为nil。字符串绘制成70%灰色。 @property(nullable, nonatomic,weak) id
// 代理,默认为空。 @property(nullable, nonatomic,strong) UIImage *background;
// 默认为nil。绘制边界矩形。图像应该是可拉伸的。 @property(nonatomic) BOOL allowsEditingTextAttributes NS_AVAILABLE_IOS(6_0);
// 默认为NO。允许使用样式操作编辑文本属性和粘贴文本。
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;
// 默认为YES。如果设置为NO,用户事件(触摸、按键)将被忽略并从事件队列中删除(此属性于UIView中继承)。
@property(nonatomic) UIKeyboardAppearance keyboardAppearance;
// 设置键盘类型,默认是UIKeyboardAppearanceDefault(此属性于UITextInputTraits中继承)。
方法:
- (BOOL)becomeFirstResponder;
//设置为第一响应者(此方法于UIResponder中继承)。
6.UITabBar、UITabBarController和UIBarButtonItem
作用:UITabBar底部导航栏(如下图),继承自UIView;UITabBarController对UITabBar进行逻辑控制,继承自UIViewController;UIBarButtonItem专门放在bar上的特殊button(如下图),继承自UIBarItem。
属性:
UITabBar:
@property(nullable, nonatomic, copy) NSArray
//获取/设置可见UITabBarItems。默认为nil。变化不是动画的。按顺序显示。
UITabBarController: @property(nullable, nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers; // 设置tabBarcontroller管理的viewcontroller。如果视图控制器的数量大于选项卡栏可显示的数量,则会自动显示“More”导航控制器。 @property(nullable, nonatomic, assign) __kindof UIViewController *selectedViewController; //当前tabBarcontroller显示的viewcontroller。 @property(nonatomic) NSUInteger selectedIndex;
//设置当前tabBarcontroller根据索引显示对应的viewcontroller。 @property(nonatomic,readonly) UITabBar *tabBar NS_AVAILABLE_IOS(3_0);
//tabBarcontroller控制的tabBar。 @property(nullable, nonatomic,weak) id
//设置代理。
方法:
UITabBar:
注意:iOS 12.1在进出navigationController后tabBar可能会存在偏移,添加如下代码: [[UITabBar appearance] setTranslucent:NO];
// 详细可参见“https://www.cnblogs.com/cui-cui/p/9957493.html”。
UIBarButtonItem:
- (instancetype)initWithTitle:(nullable NSString *)title style:(UIBarButtonItemStyle)style target:(nullable id)target action:(nullable SEL)action;
//初始化barButtonItem的标题、样式、事件。
7.UINavigationController
作用:导航栏,继承自UIViewController。
属性:
@property(nullable, nonatomic,readonly,strong) UIViewController *topViewController;
//栈上的顶视图控制器。 @property(nonatomic,readonly) UINavigationBar *navigationBar;
//控制器管理的导航栏。 @property(nonatomic,readonly,strong) UINavigationItem *navigationItem;
//按需创建,以便视图控制器可以自定义其导航外观。 @property(nullable, nonatomic,readonly,strong) UINavigationController *navigationController;
//如果这个视图控制器被推送到导航控制器上,返回它。
方法:
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController;
//使用viewcontroller初始化。
8.UIColor
作用:指定对应控件颜色。
属性:
以下为常用的颜色(使用方法举例:self.view.backgroundColor = [UIColor whiteColor];):
@property(class, nonatomic, readonly) UIColor *blackColor; // 0.0 white @property(class, nonatomic, readonly) UIColor *darkGrayColor; // 0.333 white @property(class, nonatomic, readonly) UIColor *lightGrayColor; // 0.667 white @property(class, nonatomic, readonly) UIColor *whiteColor; // 1.0 white @property(class, nonatomic, readonly) UIColor *grayColor; // 0.5 white @property(class, nonatomic, readonly) UIColor *redColor; // 1.0, 0.0, 0.0 RGB @property(class, nonatomic, readonly) UIColor *greenColor; // 0.0, 1.0, 0.0 RGB @property(class, nonatomic, readonly) UIColor *blueColor; // 0.0, 0.0, 1.0 RGB @property(class, nonatomic, readonly) UIColor *cyanColor; // 0.0, 1.0, 1.0 RGB @property(class, nonatomic, readonly) UIColor *yellowColor; // 1.0, 1.0, 0.0 RGB @property(class, nonatomic, readonly) UIColor *magentaColor; // 1.0, 0.0, 1.0 RGB @property(class, nonatomic, readonly) UIColor *orangeColor; // 1.0, 0.5, 0.0 RGB @property(class, nonatomic, readonly) UIColor *purpleColor; // 0.5, 0.0, 0.5 RGB @property(class, nonatomic, readonly) UIColor *brownColor; // 0.6, 0.4, 0.2 RGB @property(class, nonatomic, readonly) UIColor *clearColor; // 0.0 white, 0.0 alpha
方法:
+ (UIColor *)colorWithWhite:(CGFloat)white alpha:(CGFloat)alpha;
//通过设置透明度创建颜色。 + (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
//通过设置RGB以及透明度创建颜色。
注意:以上的red/green/blue/alpha的范围需在[0.0-1.0]之间。
9.UIImage和UIImageView
作用:UIImage读取png后缀的图片。UIImageView通过UIImage创建一个视图填充到控件上显示,继承自UIView。
属性:
UIImageView:
@property (nullable, nonatomic, strong) UIImage *image;
// 填充的图片。 @property (nullable, nonatomic, strong) UIImage *highlightedImage NS_AVAILABLE_IOS(3_0);
// 高亮状态的图片。
方法:
UIImage:
+ (nullable UIImage *)imageNamed:(NSString *)name;
//加载图片的名称。 - (nullable instancetype)initWithImage:(UIImage *)image NS_AVAILABLE_IOS(5_0);
//使用image初始化。
UIImageView:
- (instancetype)initWithImage:(nullable UIImage *)image;
//使用image初始化。 - (instancetype)initWithImage:(nullable UIImage *)image highlightedImage:(nullable UIImage *)highlightedImage NS_AVAILABLE_IOS(3_0);
//初始化时指定图片为image,高亮状态的图片为highlightedImage 。
10.UIScrollView
作用:创建一个滚动视图,继承自UIView。
属性:
@property(nonatomic) CGPoint contentOffset;
// 偏移。 @property(nonatomic) CGSize contentSize;
// 尺寸。 @property(nonatomic,getter=isScrollEnabled) BOOL scrollEnabled;
// 是否允许滚动,默认为YES。
11.UITableView和UITableViewCell
作用:UITableView创建一个表格视图,继承自UIScrollView;UITableViewCell创建UITableView的单元格,继承自UIView。
属性:
UITableView: @property (nonatomic, copy, nullable) UIColor *backgroundColor;
//默认背景颜色取决于样式。 @property (nonatomic, weak, nullable) id
//获取tableview中section的个数。 @property (nonatomic, readonly, nullable) NSIndexPath *indexPathForSelectedRow;
//返回nil或表示所选部分和行的索引路径。 @property (nonatomic, readonly, nullable) NSArray
//返回nil或一组表示所选部分和行的索引路径。 @property (nonatomic, strong, nullable) UIView *tableFooterView;
//视图下面的内容。默认为nil。不要与页脚混淆。
UITableViewCell: @property (nonatomic, readonly, strong, nullable) UIImageView *imageView NS_AVAILABLE_IOS(3_0);
//默认为nil。如果需要,将创建图像视图。 @property (nonatomic, readonly, strong, nullable) UILabel *textLabel NS_AVAILABLE_IOS(3_0);
// 默认为nil。如有必要,将创建标签。 @property (nonatomic, readonly, strong, nullable) UILabel *detailTextLabel NS_AVAILABLE_IOS(3_0);
//默认为nil。如果需要,将创建Label(当前样式支持详细标签)。 @property (nonatomic, readonly, strong) UIView *contentView; //UITableViewStylePlain中的单元格默认为nil, UITableViewStyleGrouped中的单元格默认为非nil。backgroundView将被添加为所有其他视图后面的子视图。
注意:如果您希望通过简单地添加其他视图来定制单元格,则应该将它们添加到内容视图中,以便在单元格进入和退出编辑模式时适当地定位它们。 @property (nonatomic, strong, nullable) UIView *backgroundView; @property (nonatomic, strong, nullable) UIView *selectedBackgroundView;
//'selectedBackgroundView'将作为backgroundView的子视图直接添加,如果不是nil,或者在所有其他视图后面。只有当单元格被选中时,它才会作为子视图添加。调用-setSelected:animated:将导致'selectedBackgroundView'以alpha淡出的方式动画化。 @property (nonatomic, getter=isSelected) BOOL selected;
//设置选定状态(标题,图像,背景)。默认为NO。动画是NO。 @property (nonatomic, getter=isHighlighted) BOOL highlighted;
//设置突出显示状态(标题,图像,背景)。默认为NO。动画是NO。 注意:Content属性。这些属性在iPhone OS 3.0中已弃用。应该使用上面的textLabel和imageView属性。 对于选定的属性,在textLabel和imageView上设置突出显示的属性。 @property (nonatomic, strong, nullable) UIColor *textColor NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
//默认为nil(文本为黑色) @property (nonatomic, strong, nullable) UIColor *selectedTextColor NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
//默认为nil(文本显示为白色) @property (nonatomic, strong, nullable) UIImage *image NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
//默认为nil。出现在标题左侧。 @property (nonatomic, strong, nullable) UIImage *selectedImage NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
// 默认为nil。
方法:
UITableView: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; //重写函数,设置tableview中Cell的高度。 - (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; //自定义头部视图。将调整为默认或指定的标题高度。 - (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section; //自定义页脚视图。将调整为默认或指定的页脚高度 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; //重写函数,设置点击tableview索引为indexPath.row处理的事件。 - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style NS_DESIGNATED_INITIALIZER; //必须在创建时指定样式。initwithframe:用UITableViewStylePlain调用它 - (nullable NSIndexPath *)indexPathForCell:(UITableViewCell *)cell; //获取Cell在tableview对应的索引,如果单元格不可见则返回nil。 - (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation; //在tableview中插入section。 - (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation; //在tableview中删除section。 - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0); //重载tableview中的section。 - (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection NS_AVAILABLE_IOS(5_0); //将tableview中section移动到索引为newSection的位置。 - (void)insertRowsAtIndexPaths:(NSArray
//注意,这将导致任何现有的删除占位符行被删除。 - (void)registerClass:(nullable Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0); //为tableview注册cell的类,一般用于注册自定义的tableViewCell。 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; //section中Cell的个数。 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; //创建cell。
12.UIAlertController和UIAlertAction
作用:UIAlertController对对话框进行逻辑控制,继承自UIViewController;UIAlertAction在对话框上的特殊button(如下图“拒绝”和“允许”),继承自NSObject。
属性:
UIAlertController:
@property (nonatomic, readonly) NSArray
UIAlertAction:
@property (nullable, nonatomic, readonly) NSString *title; //alertAction上显示的标题。 @property (nonatomic, readonly) UIAlertActionStyle style; //alertAction的样式,如:UIAlertActionStyleDefault(默认字体),UIAlertActionStyleCancel(加粗字体), UIAlertActionStyleDestructive(红色警示字体)。
方法:
UIAlertController:
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle; //设置对话框的title、message、style(UIAlertControllerStyleActionSheet以表格形式竖向展示alertAction,UIAlertControllerStyleAlert如上图样式横向展示alertAction)。 - (void)addAction:(UIAlertAction *)action; //将alertAction添加到alertController。 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion NS_AVAILABLE_IOS(5_0); //注意:此函数不可在viewDidLoad未执行完成前 运行。具体可参考:https://www.cnblogs.com/kelejiabing/p/4846214.html。
UIAlertAction:
+ (instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction *action))handler; //设置点击alertAction后的处理为handler。
13.UIApplication
作用:每个APP有且仅有一个UIApplication的对象(大多由系统创建)。可以进行一些应用层级的操作。继承自UIResponder。
程序完整启动流程:
1.执行Main
2.执行UIApplicationMain函数.
3.创建UIApplication对象,并设置UIApplicationMain对象的代理.UIApplication的第三个参数就是UIApplication的名称,如果指定为nil,它会默认 为UIApplication.UIApplication的第四个参数为UIApplication的代理.
4.开启一个主运行循环.保证应用程序不退出.
5.加载info.plist.加载配置文文件.判断一下info.plist文件当中有没有Main storyboard file base name里面有没有指定storyboard文件,如果有就去加载info.plist文件,如果没有,那么应用程序加载完毕.
6.通知应用程序,调用代理方法
引用自:https://www.cnblogs.com/stronger-ios-lcx/p/5629542.html。
属性:
@property(nonatomic,readonly) NSArray<__kindof UIWindow *> *windows; //不包括有系统创建和管理的窗口。
方法:
+ (UIApplication *)sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead."); //获取app的UIApplication实例。 - (BOOL)canOpenURL:(NSURL *)url NS_AVAILABLE_IOS(3_0); //判断URL是否可用。 - (void)openURL:(NSURL*)url options:(NSDictionary
14.UIPasteboard
作用:获取/更改粘贴板内容。继承自NSObject。
属性:
@property(nullable,nonatomic,copy) NSString *string __TVOS_PROHIBITED __WATCHOS_PROHIBITED; //粘贴板保存的字符串。 @property(nullable,nonatomic,copy) NSURL *URL __TVOS_PROHIBITED __WATCHOS_PROHIBITED; //粘贴板保存的URL资源。 @property(nullable,nonatomic,copy) UIImage *image __TVOS_PROHIBITED __WATCHOS_PROHIBITED; //粘贴板保存的图像。 @property(nullable,nonatomic,copy) UIColor *color __TVOS_PROHIBITED __WATCHOS_PROHIBITED; //粘贴板保存的颜色。
方法:
+ (UIPasteboard *)generalPasteboard; //获取一个自定义的剪切板。
15.UIProgressView
作用:进度条,根据进度更新显示。继承自UIView。
属性:
@property(nonatomic) UIProgressViewStyle progressViewStyle; //默认样式为UIProgressViewStyleDefault。 @property(nonatomic) float progress; //从0.0 到1.0, 默认是0.0,更改此属性更新进度。 @property(nonatomic, strong, nullable) UIColor* progressTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; //进度条已加载颜色。 @property(nonatomic, strong, nullable) UIColor* trackTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; //进度条未加载颜色。
方法:
- (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER; //初始化时设置进度条的位置及尺寸。
16.WKWebView
作用:加载网页,iOS 8以后从UIWebView替换为WKWebView,WKWebView优化了加载速度以及内存占用问题。继承自UIView。
注意:添加实例时需要导入头文件【#import "WebKit/WebKit.h"】。
属性:
@property (nullable, nonatomic, weak) id
@property (nonatomic, readonly) double estimatedProgress;
//对当前导航已经完成的部分的估计。(加载网页时,可以将此属性赋值到UIProgressView实例的progress属性)。
方法:
- (nullable WKNavigation *)loadRequest:(NSURLRequest *)request; //摘要request的URL,例:[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com/"]]]; - (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(nullable void *)context; //用于观察接收器价值对的注册或注销。
17.UISwitch
作用:开关按钮。继承自UIControl。
属性:
@property(nonatomic,getter=isOn) BOOL on;
//UISwitch开关的状态。
方法:
- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
//点击按钮切换开关状态之后处理的事件。
18.相机相关的类(概述)
AVAuthorizationStatus 检验是否已授权。AVCaptureSession使用会话管理输入和输出设备的数据流。AVCaptureDevice提供实时输入媒体数据的物理设备。AVCaptureVideoPreviewLayer预览摄像头时实时显示视频内容。AVCaptureDeviceInput/AVCaptureMetadataOutput输入/输出流。AVMetadataMachineReadableCodeObject从媒体流中解析出的可读代码(如条形码等)。
19.画图相关的类(概述)
UIBezierPath在自定义的 View 中绘制和渲染由直线和曲线组成的路径,具体可参见https://www.cnblogs.com/Hakim/p/5585198.html。CAShapeLayer根据路径绘图(一般搭配UIBezierPath一起使用),具体可参见https://www.cnblogs.com/lxlx1798/p/9470653.html。CGAffineTransform在二维空间做旋转,缩放和平移,具体参见https://www.cnblogs.com/xujinzhong/p/11155076.html。CABasicAnimation 动画会沿着设定的起始点、终点、时间进行移动,具体可参见https://www.cnblogs.com/wengzilin/p/4250957.html。
推荐链接
发表评论