#define TICK \
NSLog(@">>>> Begin");\
CFTimeInterval begin = CACurrentMediaTime();
#define TOCK \
CFTimeInterval end = CACurrentMediaTime();\
NSLog(@"%@", [NSString stringWithFormat:@"%@ - %@ms",NSStringFromClass([self class]), @(1000 * (end - begin))]);\
NSLog(@"<<<< End");
在想要查看执行时间的代码的地方进行这么处理
TICK
//do your work here
TOCK
在使用view的缩放的时候,layer.border.width随着view的放大,会出现锯齿化的问题,解决这个问题需要设置这个属性。
self.layer.allowsEdgeAntialiasing = YES;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
return [target performSelector:action withObject:params];
#pragma clang diagnostic pop
UINavigationController
有个 Property
,是一个存储所有 push
进 navigationcontroller
的视图的集合,是一个栈结构,当我们要 pop
到某个 ViewController
的时候,直接用 for in
去遍历 viewControllers
即可:
for (UIViewController viewController in self.navigationController.viewControllers) {
if ([viewController isKindOfClass:[AccountManageViewController class]]) {
[self.navigationController popToViewController:viewController animated:YES];
}
}
为了做到数据与视图的分离,我们一般会将一个页面的局部视图以自定义 UIView
的方式独立出来,如果在该视图中有触发事件(事件处理不需要父视图的上下文),就会遇到在 UIView
中获取 UIViewController
的情况,可以写一个 UIView
的范畴 UIView(UIViewController)
:
#pragma mark - 获取当前view的viewcontroller
+ (UIViewController *)getCurrentViewController:(UIView *) currentView {
for (UIView* next = [currentView superview]; next; next = next.superview) {
UIResponder *nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextResponder;
}
}
return nil;
}
一般我们在Podfile文件中指定在某个特定的scheme下引用某个框架,写法如下:
pod 'PgyUpdate', :configurations => ['Adhoc','AdhocDebug']
pod 'Reveal-iOS-SDK', '1.5.1', :configurations => ['Debug']
可以指定某个自定义框架的地址:
pod 'zucheLib_Category', :git => 'http://10.3.4.127:8888/ios_team/zuchelib_category.git', :tag => ‘0.1.2’
如果在自定义的框架下,我们使用#if DEBUG这种定义模式来区分,那么在默认Pods中是无效的。需要使用以下方法打开Debug的编译配置:
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
if target.name == 'zucheLib_Networking'
target.build_configurations.each do |config|
if config.name != 'Release'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'DEBUG=1']
end
end
end
end
end
如果多个target都需要引用某些公共的Pods类库框架可以使用如下写法:
def shared_pods
platform :ios, '7.0'
inhibit_all_warnings! # 关闭所有警告
#network
pod 'AFNetworking', '~> 3.0'
end
target "XXXXXXX" do
shared_pods
end