首页 技术 正文
技术 2022年11月11日
0 收藏 335 点赞 4,312 浏览 3324 个字

1.手写冒泡跟插入排序

冒泡排序来源于生活常识,相当于把数组竖起来,轻的向上,重的向下。
void bubbleSort(int[] unsorted)
{
for (int i = ; i < unsorted.Length; i++)
{
for (int j = i; j < unsorted.Length; j++)
{
if (unsorted[i] > unsorted[j]) {
int temp = unsorted[i];
unsorted[i] = unsorted[j];
unsorted[j] = temp;
}
}
}
}
插入排序,有点类似打斗地主时候摸牌配顺子,345678910JQKA,先抽到3,5又抽到4就把4插在3,5之间。
void insertSort(int *a,int n)
{
int i,j,key; // 控制需要插入的元素
for (i = ; i < n; i++)
{
// key为要插入的元素
key = a[i];
// 查找要插入的位置,循环结束,则找到插入位置
for (j = i; j > && a[j-] > key; j--)
{
// 移动元素的位置,供要插入元素使用
a[j] = a[j-];
} // 插入需要插入的元素
a[j] = key;
}
}

2.重写setter/getter方法

 假设声明属性
@property (nonatomic, copy) NSString *imageName;
这里一旦连setter,getter方法都重写,编译器不会给我们自动生成成员变量_imageName,因此我们需要在类的声明中添加一个成员变量_ImageName:
@interface Demo () {
NSString *_imageName;
}
@end
一,ARC中
- (void)setImageName:(NSString *)aName {
if (_imageName != aName) {
_imageName = nil;
_imageName = [aName copy];
}
}
- (NSString *)imageName {
return _imageName;
}
二,MRC中
- (void)setImageName:(NSString *)aName {
if (_imageName != aName) {
[_imageName release];
_imageName = nil;
_imageName = [aName copy];
}
}
- (NSString *)imageName {
return _imageName;

3.手写简单的单例

+ (instancetype)shared {
static XNGUserManager *sg_userManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (sg_userManager == nil) {
sg_userManager = [[XNGUserManager alloc] init];
}
}); return sg_userManager;
}

4.谈谈iOS中的通知

一,获取通知对象:
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
二,通知对象的三个属性
@property (readonly, copy) NSString *name;//通知的名称
@property (nullable, readonly, retain) id object;//通知的发布者
@property (nullable, readonly, copy) NSDictionary *userInfo;//额外的信息,可以储存一些数据
三,通知对象的初始方法
- (instancetype)initWithName:(NSString *)name
object:(nullable id)object
userInfo:(nullable NSDictionary *)userInfo;
+ (instancetype)notificationWithName:(NSString *)aName
object:(nullable id)anObject;
+ (instancetype)notificationWithName:(NSString *)aName
object:(nullable id)anObject
userInfo:(nullable NSDictionary *)aUserInfo;
四,发布通知的三种方法
- (void)postNotification:(NSNotification *)notification;
- (void)postNotificationName:(NSString *)aName
object:(nullable id)anObject;
- (void)postNotificationName:(NSString *)aName
object:(nullable id)anObject
userInfo:(nullable NSDictionary *)aUserInfo;

五,注册通知
- (void)addObserver:(id)observer
selector:(SEL)aSelector
name:(nullable NSString *)aName
object:(nullable id)anObject;- (id <NSObject>)addObserverForName:(nullable NSString *)name
object:(nullable id)obj
queue:(nullable NSOperationQueue *)queue
usingBlock:(void (^)(NSNotification *note))block
六,取消注册通知
- (void)removeObserver:(id)observer;- (void)removeObserver:(id)observer
name:(nullable NSString *)aName
object:(nullable id)anObject;
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

5.UIView与CLayer有何区别

).UIView 是 iOS 系统中界面元素的基础,所有的界面元素都是继承自它。它本身完全是由 CoreAnimation 来实现的。
它真正的绘图部分,是由一个 CALayer 类来管理。 UIView 本身更像是一个 CALayer 的管理器,访问它的跟绘图和跟坐标有关的属性。).UIView 有个重要属性 layer ,可以返回它的主 CALayer 实例。).UIView 的 CALayer 类似 UIView 的子 View 树形结构,也可以向它的 layer 上添加子layer ,来完成某些特殊的表示。
即 CALayer 层是可以嵌套的。).UIView 的 layer 树形在系统内部,被维护着三份 copy 。分别是逻辑树,这里是代码可以操纵的;
动画树,是一个中间层,系统就在这一层上更改属性,进行各种渲染操作;显示树,其内容就是当前正被显示在屏幕上得内容。).动画的运作:对 UIView 的 subLayer (非主 Layer )属性进行更改,系统将自动进行动画生成,动画持续时间的缺省值似乎是 0.5 秒。).坐标系统: CALayer 的坐标系统比 UIView 多了一个 anchorPoint 属性,使用CGPoint 结构表示,值域是 ~ ,是个比例值。
这个点是各种图形变换的坐标原点,同时会更改 layer 的 position 的位置,它的缺省值是 {0.5,0.5} ,即在 layer 的中央。).渲染:当更新层,改变不能立即显示在屏幕上。当所有的层都准备好时,可以调用setNeedsDisplay 方法来重绘显示。).变换:要在一个层中添加一个 3D 或仿射变换,可以分别设置层的 transform 或affineTransform 属性。).变形: Quartz Core 的渲染能力,使二维图像可以被自由操纵,就好像是三维的。
图像可以在一个三维坐标系中以任意角度被旋转,缩放和倾斜。 CATransform3D 的一套方法提供了一些魔术般的变换效果。
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,994
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,508
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,351
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,135
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,768
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,846