码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发工程师面试题(二)

时间:2016-05-06 21:47:56      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:

1.手写冒泡跟插入排序

冒泡排序来源于生活常识,相当于把数组竖起来,轻的向上,重的向下。
void
bubbleSort(int[] unsorted) { for (int i = 0; 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 = 1; i < n; i++) { // key为要插入的元素 key = a[i]; // 查找要插入的位置,循环结束,则找到插入位置 for (j = i; j > 0 && a[j-1] > key; j--) { // 移动元素的位置,供要插入元素使用 a[j] = a[j-1]; } // 插入需要插入的元素 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有何区别

1).UIView 是 iOS 系统中界面元素的基础,所有的界面元素都是继承自它。它本身完全是由 CoreAnimation 来实现的。
它真正的绘图部分,是由一个 CALayer 类来管理。 UIView 本身更像是一个 CALayer 的管理器,访问它的跟绘图和跟坐标有关的属性。
2).UIView 有个重要属性 layer ,可以返回它的主 CALayer 实例。 3).UIView 的 CALayer 类似 UIView 的子 View 树形结构,也可以向它的 layer 上添加子layer ,来完成某些特殊的表示。
即 CALayer 层是可以嵌套的。
4).UIView 的 layer 树形在系统内部,被维护着三份 copy 。分别是逻辑树,这里是代码可以操纵的;
动画树,是一个中间层,系统就在这一层上更改属性,进行各种渲染操作;显示树,其内容就是当前正被显示在屏幕上得内容。
5).动画的运作:对 UIView 的 subLayer (非主 Layer )属性进行更改,系统将自动进行动画生成,动画持续时间的缺省值似乎是 0.5 秒。 6).坐标系统: CALayer 的坐标系统比 UIView 多了一个 anchorPoint 属性,使用CGPoint 结构表示,值域是 0~1 ,是个比例值。
这个点是各种图形变换的坐标原点,同时会更改 layer 的 position 的位置,它的缺省值是 {0.5,0.5} ,即在 layer 的中央。 7).渲染:当更新层,改变不能立即显示在屏幕上。当所有的层都准备好时,可以调用setNeedsDisplay 方法来重绘显示。 8).变换:要在一个层中添加一个 3D 或仿射变换,可以分别设置层的 transform 或affineTransform 属性。 9).变形: Quartz Core 的渲染能力,使二维图像可以被自由操纵,就好像是三维的。
图像可以在一个三维坐标系中以任意角度被旋转,缩放和倾斜。 CATransform3D 的一套方法提供了一些魔术般的变换效果。

iOS开发工程师面试题(二)

标签:

原文地址:http://www.cnblogs.com/iOSlearner/p/5467050.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!