前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS 开发小技巧

iOS 开发小技巧

作者头像
s_在路上
发布2018-09-30 10:55:57
7470
发布2018-09-30 10:55:57
举报
文章被收录于专栏:iOS 开发杂谈iOS 开发杂谈

如何快速的查看一段代码的执行时间。

代码语言:javascript
复制
#define TICK \
    NSLog(@">>>> Begin");\
    CFTimeInterval begin = CACurrentMediaTime();

#define TOCK \
    CFTimeInterval end = CACurrentMediaTime();\
    NSLog(@"%@", [NSString stringWithFormat:@"%@ - %@ms",NSStringFromClass([self class]), @(1000 * (end - begin))]);\
    NSLog(@"<<<< End");

在想要查看执行时间的代码的地方进行这么处理

代码语言:javascript
复制
TICK
//do your work here
TOCK

view 的锯齿化的问题

在使用view的缩放的时候,layer.border.width随着view的放大,会出现锯齿化的问题,解决这个问题需要设置这个属性。

代码语言:javascript
复制
self.layer.allowsEdgeAntialiasing = YES;
忽略不必要的警告⚠️
代码语言:javascript
复制
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
        return [target performSelector:action withObject:params];
#pragma clang diagnostic pop
pop 到指定 ViewController

UINavigationController 有个 Property,是一个存储所有 pushnavigationcontroller 的视图的集合,是一个栈结构,当我们要 pop 到某个 ViewController 的时候,直接用 for in 去遍历 viewControllers 即可:

代码语言:javascript
复制
for (UIViewController viewController in self.navigationController.viewControllers) {
    if ([viewController isKindOfClass:[AccountManageViewController class]]) {
        [self.navigationController popToViewController:viewController animated:YES];
    }
}
通过 View 获取 ViewController

为了做到数据与视图的分离,我们一般会将一个页面的局部视图以自定义 UIView 的方式独立出来,如果在该视图中有触发事件(事件处理不需要父视图的上下文),就会遇到在 UIView 中获取 UIViewController 的情况,可以写一个 UIView 的范畴 UIView(UIViewController)

代码语言:javascript
复制
#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;
}
iOS cocoapods一些用法备忘

一般我们在Podfile文件中指定在某个特定的scheme下引用某个框架,写法如下:

代码语言:javascript
复制
pod 'PgyUpdate', :configurations => ['Adhoc','AdhocDebug']
pod 'Reveal-iOS-SDK', '1.5.1', :configurations => ['Debug']

可以指定某个自定义框架的地址:

代码语言:javascript
复制
pod 'zucheLib_Category', :git => 'http://10.3.4.127:8888/ios_team/zuchelib_category.git', :tag => ‘0.1.2’

如果在自定义的框架下,我们使用#if DEBUG这种定义模式来区分,那么在默认Pods中是无效的。需要使用以下方法打开Debug的编译配置:

代码语言:javascript
复制
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类库框架可以使用如下写法:

代码语言:javascript
复制
def shared_pods
   platform :ios, '7.0'
   inhibit_all_warnings!  # 关闭所有警告
   #network
   pod 'AFNetworking', '~> 3.0'
end
target "XXXXXXX" do
   shared_pods
end
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.09.14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 如何快速的查看一段代码的执行时间。
  • view 的锯齿化的问题
    • 忽略不必要的警告⚠️
      • pop 到指定 ViewController
        • 通过 View 获取 ViewController
          • iOS cocoapods一些用法备忘
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档