Skip to content

Instantly share code, notes, and snippets.

@wangzz
Created August 12, 2014 07:54
Show Gist options
  • Save wangzz/90a57629143d6d38f0b8 to your computer and use it in GitHub Desktop.
Save wangzz/90a57629143d6d38f0b8 to your computer and use it in GitHub Desktop.
记录遇到的小的知识点。
记录遇到的小的知识点。
@wangzz
Copy link
Author

wangzz commented Aug 18, 2014

Apple关于deprecated方法的描述:

Deprecation does not mean the immediate deletion of an interface from a framework or library. It is simply a way to flag interfaces for which better alternatives exist. You can use deprecated APIs in your code. However, Apple recommends that you migrate to newer interfaces as soon as possible because deprecated APIs may be deleted from a future version of the OS. Check the header files or documentation of the deprecated API for information about any recommended replacement interfaces.

deprecated并不意味着该方法会立马被删除,而是它有了更好的替代方法。开发者需要尽快将标为deprecated的方法替换掉,因为Apple可能在将来的某个系统版本中会将其删除。

@wangzz
Copy link
Author

wangzz commented Aug 19, 2014

Base SDK and Deployment Target Settings

  • Deployment Target

该设置项标识软件支持的最低系统版本。Deployment Target和比它早的系统的特性都可以无条件使用。

  • Base SDK

标识应用能支持的最高系统版本。默认情况下Xcode会将该选项设置为当前最新的系统版本。

二者之间的关系如图所示:

Deployment Target and Base SDK

PS:

  • iOS或OS X 的SDK中的libraries仅仅用于链接,它们本身并不包含任何可执行文件。SDK只有和编译目标机器配合才能正常工作。
  • 当使用Simulator SDKs编译的时候,生成的二进制文件只使用Base SDK指定的系统版本,即和Deployment Target指定的系统版本没有直接关系。

@wangzz
Copy link
Author

wangzz commented Aug 27, 2014

Mac,iOS界面中的坐标系

话说Mac,iOS中的各种坐标系总会让初学者摸不着头脑,一会儿这样一会儿那样。不过有一点是不变的,z轴的正方向总是指向观察者,也就是垂直屏幕平面向上。

1.NSView坐标系
在Mac中NSView的坐标系默认是右手坐标系(View其实是二维坐标系,但是为了方便我们可以假设其是三维坐标系,只是所有界面的变化都是在xy平面上),原点在左下角. NSView提供了一个可以用于覆盖的方法

- (BOOL)isFlipped;

此默认返回NO,当返回YES的时候,则坐标系变成左手坐标系,坐标原点变成左上角。

在Mac的AppKit中有很多界面组件本身就使用了Flipped Coordinate System(覆盖了上面的方法并返回YES),如NSButton,NSTableview,NSSplitView 更详细的看这里 其中Cocoa Use of Flipped Coordinates 这一节 https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html

2.UIView坐标系
而在iOS的UIView中,则没有所谓的Flipped Coordinate的概念,统一使用左手坐标系,也就是坐标原点在左上角.

3.Quartz坐标系
Quartz(Core Graphics)坐标系使用的右手坐标系,原点在左下角,所以所有使用Core Graphics画图的坐标系都是右手坐标系,当使用CG的相关函数画图到UIView上的时候,需要注意CTM的Flip变换,要不然会出现界面上图形倒过来的现象。由于UIKit的提供的高层方法会自动处理CTM(比如UIImage的drawInRect方法),所以无需自己在CG的上下文中做处理。 参见Quartz 2D Coordinate Systems

4.CALayer坐标系
这个有些变态了,其坐标系和平台有关,在Mac中CALayer使用的是右手坐标系,其原点在左下角;iOS中使用的左手坐标系,其原点在左上角。 参见 Layer Coordinate System

引至:http://geeklu.com/2012/06/3d-coordinate-system/

@wangzz
Copy link
Author

wangzz commented Feb 10, 2015

hit-test

  • 流程

hit-test使用的是逆序递归遍历法:

It implements it by searching the view hierarchy using reverse pre-order depth-first traversal algorithm.

比如window上先后添加了A、B、C三个view:
traversal

那么屏幕上任何一点发生触摸事件时都会按如下顺序遍历:

** C 如果在C上继续递归遍历C的subview,不在C上则遍历B
** B 如果在B上继续递归遍历B的subview,不在B上则遍历A
** A 如果在A上继续递归遍历A的subview,不在A上则遍历A的上一级

直到找到一个包含点击区域的最上层view。

  • 关于多次调用hit-test

** iOS6 及之前系统会重复调用三次hit-test流程;
** iOS7 及之后系统会重复调用两次hit-test流程。

调用那么多次的原因不明。

  • 关于UITabbarController

点击包含UITabBar、UIToolBar等控件上方40像素区域内时,多次hit-test的最后一次中point值会发生随机变化,point的Y值会被增大若干不等的像素。

原因未知。

参考链接: Hit-Testing in iOS

@wangzz
Copy link
Author

wangzz commented Apr 13, 2015

升级Xcode插件失效解决办法

  • 查看Xcode对应版本的UUID:
tail -f /var/log/system.log
  • 更新插件配置文件

得到UUID后执行命令:

find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add XCode_UUID
  • 参考链接:

XCode升级后插件失效的原理与修复办法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment