小技巧

来源:互联网 发布:2017最火的网络电视剧 编辑:程序博客网 时间:2024/06/13 05:51

TableView不显示没内容的Cell怎么办?

自 http://www.cocoachina.com/ios/20150320/11384.html

类似这种,我不想让下面那些空的显示.

01.png

很简单.

1
self.tableView.tableFooterView = [[UIView alloc] init];

试过的都说好.

加完这句之后就变成了这样.

02.png

自定义了leftBarbuttonItem左滑返回手势失效了怎么办?

1
2
3
4
5
6
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
                                         initWithImage:img
                                         style:UIBarButtonItemStylePlain
                                         target:self
                                         action:@selector(onBack:)];
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;

ScrollView莫名其妙不能在viewController划到顶怎么办?

1
self.automaticallyAdjustsScrollViewInsets = NO;

键盘事件写的好烦躁,都想摔键盘了,怎么办?

1.买个结实的键盘.

2.使用IQKeyboardManager(github上可搜索),用完之后腰也不疼了,腿也不酸了.

为什么我的app老是不流畅,到底哪里出了问题?

如图

03.gif

这个神器叫做:KMCGeigerCounter,快去github搬运吧.

怎么在不新建一个Cell的情况下调整separaLine的位置?

1
_myTableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0);

怎么点击self.view就让键盘收起,需要添加一个tapGestures么?

1
2
3
4
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
   [self.view endEditing:YES];
}

怎么给每个ViewController设定默认的背景图片?

使用基类啊,少年。

想在代码里改在xib里添加的layoutAttributes,但是怎么用代码找啊?

像拉button一样的拉你的约束.nslayoutattribute也是可以拉线的.

怎么像safari一样滑动的时候隐藏navigationbar?

1
navigationController.hidesBarsOnSwipe = Yes

导航条返回键带的title太讨厌了,怎么让它消失!

1
2
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                     forBarMetrics:UIBarMetricsDefault];

CoreData用起来好烦,语法又臭又长,怎么办?

MagicRecord

CollectionView 怎么实现tableview那种悬停的header?

CSStickyHeaderFlowLayou

能不能只用一个pan手势来代替UISwipegesture的各个方向?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
- (void)pan:(UIPanGestureRecognizer *)sender
{
typedef NS_ENUM(NSUInteger, UIPanGestureRecognizerDirection) {
    UIPanGestureRecognizerDirectionUndefined,
    UIPanGestureRecognizerDirectionUp,
    UIPanGestureRecognizerDirectionDown,
    UIPanGestureRecognizerDirectionLeft,
    UIPanGestureRecognizerDirectionRight
};
static UIPanGestureRecognizerDirection direction = UIPanGestureRecognizerDirectionUndefined;
switch (sender.state) {
    case UIGestureRecognizerStateBegan: {
        if (direction == UIPanGestureRecognizerDirectionUndefined) {
            CGPoint velocity = [sender velocityInView:recognizer.view];
            BOOL isVerticalGesture = fabs(velocity.y) > fabs(velocity.x);
            if (isVerticalGesture) {
                if (velocity.y > 0) {
                    direction = UIPanGestureRecognizerDirectionDown;
                else {
                    direction = UIPanGestureRecognizerDirectionUp;
                }
            }
            else {
                if (velocity.x > 0) {
                    direction = UIPanGestureRecognizerDirectionRight;
                else {
                    direction = UIPanGestureRecognizerDirectionLeft;
                }
            }
        }
        break;
    }
    case UIGestureRecognizerStateChanged: {
        switch (direction) {
            case UIPanGestureRecognizerDirectionUp: {
                [self handleUpwardsGesture:sender];
                break;
            }
            case UIPanGestureRecognizerDirectionDown: {
                [self handleDownwardsGesture:sender];
                break;
            }
            case UIPanGestureRecognizerDirectionLeft: {
                [self handleLeftGesture:sender];
                break;
            }
            case UIPanGestureRecognizerDirectionRight: {
                [self handleRightGesture:sender];
                break;
            }
            default: {
                break;
            }
        }
        break;
    }
    case UIGestureRecognizerStateEnded: {
        direction = UIPanGestureRecognizerDirectionUndefined;   
        break;
    }
    default:
        break;
}
}

拉伸图片的时候怎么才能让图片不变形?
1.UIImage *image = [[UIImage imageNamed:@"xxx"] stretchableImageWithLeftCapWidth:10 topCapHeight:10];

2.

05.gif


怎么播放GIF的时候这么卡,有没有好点的库?

FlipBoard出品的太适合你了:https://github.com/Flipboard/FLAnimatedImage

怎么一句话添加上拉刷新?

https://github.com/samvermette/SVPullToRefresh

1
2
3
4
[tableView addPullToRefreshWithActionHandler:^{
// prepend data to dataSource, insert cells at top of table view
// call [tableView.pullToRefreshView stopAnimating] when done
} position:SVPullToRefreshPositionBottom];

怎么把tableview里cell的小对勾的颜色改成别的颜色?

1
_mTableView.tintColor = [UIColor redColor];

04.png

本来我的statusbar是lightcontent的,结果用UIImagePickerController会导致我的statusbar的样式变成黑色,怎么办?

1
2
3
4
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

怎么把我的navigationbar弄成透明的而不是带模糊的效果?

1
2
3
4
[self.navigationBar setBackgroundImage:[UIImage new]
                         forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;

怎么改变uitextfield placeholder的颜色和位置?

继承uitextfield,重写这个方法

1
2
3
4
- (void) drawPlaceholderInRect:(CGRect)rect {
    [[UIColor blueColor] setFill];
    [self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment];
}

iOS 开发的9个超有用小技巧

2015-03-20 10:41 编辑: suiling 分类:iOS开发 来源:kissGod的简书
 19 13426
招聘信息:
  • iOS 创意工程师
  • Java高级工程师
  • iOS高级开发工程师(急招)
  • java开发工程师
  • 开发工程师
  • 「上海 · 食色」招聘 Android/IOS 工程师
  • 游戏服务器端开发工程师
  • Android开发工程师
  • 杭州网易iOS实习开发工程师
  • 杭州网易iOS开发工程师
  • 高级Java工程师
 

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

1
2
#define TICK   NSDate *startTime = [NSDate date]
#define TOCK   NSLog(@"Time: %f", -[startTime timeIntervalSinceNow])

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

1
2
3
TICK
//do your work here
TOCK

2.如何快速查看一个函数的调用次数,且不添加一句代码。 如下图

1.jpg

这种方法适合于一个if方法,一个for循环,而且不会中断程序,切不需要加一句代码。但是一定要记得选中下面的automatically continue after evaluting actions;

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

1
self.layer.allowsEdgeAntialiasing = YES;

4.instrument中time profile中的self, #self,%self各代表什么 ?

2.jpg

下面引用了一下网上的具体内容

“Self is "The number of times the symbol calls itself." according to the Apple Docs on the Time Profiler.

From the way the numbers look though, it seems self is the summed duration of samples that had this symbol at the bottom of its stack trace. That would make:

self: the number of samples where this symbol was at the bottom of the stack trace

% self: the percent of self samples relative to total samples of currently displayed call tree

(eg - #self / total samples).

So this wouldn't tell you how many times a method was called. But it would give you an idea how much time is spent in a method or lower in the call tree.”

5.如何快速添加一个全局异常断点,(一步顶三步)。和添加一个symbloic断点,(一步还是顶三步)添加一个断点不使用鼠标

1426819934867664.gif

看到图了吧,加这些断点完全不需要动一下鼠标(恕我吹牛B了),加单独断点的时候动了下鼠标,但那是我故意让你们看到我是有鼠标的。

  • 首先All Exception断点是我们很常用的,这个我是这样用一个快捷键做到的!通过改键command +p 为加异常断点的,要说怎么改,翻我以前博客去!

  • 然后加symbloic的快捷键为commnamd + option + \

  • 加一个单独一行断点的快捷键为command + \

6.在iOS开发中我们在和产品和设计沟通的时候我们经常需要截取手机的屏幕或者模拟器上的屏幕,我们用手机可能会使用 Home 键 + 开机键,然后再通过 iPhoto 或者在手机用 qq 传过去,但是我教大家一个方法直接使用快捷键截取手机上的图到电脑桌面上。

具体方法见下图 :

4.jpg

在 Xcode的 debug菜单中找到viewDebugging,即使当前程序没有运行,也可以直接截取手机上的图片直接到桌面。(哈哈哈这样再不需要TM的按TM的手机上的按键再用 iPhoto拷贝到桌面了)。年轻人你以为这样就完了吗!?你还是太稚嫩啊,谁TM的想找到这个debug菜单再找到下面的一堆东西,当然要改成快捷键了,如何做看下图。

5.jpg

看到这个血淋漓的红色的箭头了嘛,你首先找到 debug 的快捷键菜单项,在把它改成 ?+?这个,这时候有冲突了怎么办?你不知道有没有影响到其他快捷键怎么办,小傻瓜,改呗!把以前的这个功能去掉?+?(ps:以前的就是 show complete list 如同点击一个?一个效果,那你还要它做嘛啊?),为什么改成这个份听哥的,你改成这个绝壁会用着特别爽。(好了以后要给产品还是设计发图分分钟的事情了~~)

7.iOS调试技巧只显示图片的对齐尺寸和 frame。

我记得以前一个说显示对齐尺寸的,他是这么做的:

“在应项目的Edit Scheme中设置一个启动参数 UIViewShowAlignmentRects并将参数值设置为YES,可以让程序在运行时显示视图的对齐矩阵(alignment rectangle)。”

我当时看完就不屑一顾,这么复杂谁用啊。你们真的以为我再装b嘛,好吧,你们猜对了,我确实在装b,你们看下面的效果就知道我为什么在装b了。

1426820189693015.gif

可能我图片切换的比较快,效果你们没看的明显。你们可以自己试下,这个可以随时切换是否显示ShowAlignmentRect,或者每一个控件的尺寸包括系统的控件(譬如系统的 uibutton 它会显示内部的 imageview 的尺寸和 label 的尺寸然后用不同的颜色区别,xcode 颜色区分的还是相当美观的)

这尼玛可是大杀器了,有了这个你的控件的大小位置是否显示都根本不用我前面所说的 lldb 了,而且方便快捷,你问我是怎么做的,我可没配置辣么多的一对参数,我也懒得记,当然我是用快捷键了!细心的同学可能会注意到前面的 截图viewDebuging中有showViewFrame 和ShowAlignmentRects,当然点击这些菜单就会出现我这些效果了,我当然又是改快捷键了,我时间很宝贵的。

8.在我们开发中经常使用 git,然后我们修改了这个文件不知道哪里改错了,我们经常需要恢复这个文件,这样我们可能会切到终端,也可能会直接使用 xcode来去放弃文件的修改,幸好xcode对 source Control支持的比较好,所以我们可以通过修改这些方式的快捷键来快速恢复文件,下面是我的一些设置,用好了绝壁提高你的效率.

7.jpg

对于我来说常用的也就是放弃当前文件的修改和放弃所有文件的修改,和翻看git History如果当前文件修改的时候怎么都回退不到正确的,这几个东西可起大作用了!

9.在 iOS 中我们经常会碰到一些imagView的UIContentMode的显示方式,最初我怎么记也搞不太清楚,后来我看到了这幅图,我发现我遇到了指明灯了,一图解千惑,这里分享给大家。(ps:大家别说我菜啊)

8.jpg

0 0
原创粉丝点击