TableView不顯示沒內(nèi)容的Cell怎樣辦?
類似這類,我不想讓下面那些空的顯示.
很簡單.
1
|
self.tableView.tableFooterView = [[UIView alloc] init];
|
試過的都說好.
加完這句以后就變成了這樣.
自定義了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.買個(gè)結(jié)實(shí)的鍵盤.
2.使用IQKeyboardManager(github上可搜索),用完以后腰也不疼了,腿也不酸了.
為何我的app總是不流暢,到底哪里出了問題?
如圖
這個(gè)神器叫做:KMCGeigerCounter,快去github搬運(yùn)吧.
怎樣在不新建1個(gè)Cell的情況下調(diào)劑separaLine的位置?
1
|
_myTableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0);
|
怎樣點(diǎn)擊self.view就讓鍵盤收起,需要添加1個(gè)tapGestures么?
1
2
3
4
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
|
怎樣給每一個(gè)ViewController設(shè)定默許的背景圖片?
使用基類啊,少年。
想在代碼里改在xib里添加的layoutAttributes,但是怎樣用代碼找啊?
像拉button1樣的拉你的束縛.nslayoutattribute也是可以拉線的.
怎樣像safari1樣滑動(dòng)的時(shí)候隱藏navigationbar?
1
|
navigationController.hidesBarsOnSwipe = Yes
|
導(dǎo)航條返回鍵帶的title太討厭了,怎樣讓它消失!
1
2
|
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, ⑹0)
forBarMetrics:UIBarMetricsDefault];
|
CoreData用起來好煩,語法又臭又長,怎樣辦?
MagicRecord
CollectionView 怎樣實(shí)現(xiàn)tableview那種懸停的header?
CSStickyHeaderFlowLayou
能不能只用1個(gè)pan手勢來代替UISwipegesture的各個(gè)方向?
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;
}
}
|
拉伸圖片的時(shí)候怎樣才能讓圖片不變形?
1.UIImage *image = [[UIImage imageNamed:@"xxx"] stretchableImageWithLeftCapWidth:10 topCapHeight:10];
2.
怎樣播放GIF的時(shí)候這么卡,有無好點(diǎn)的庫?
FlipBoard出品的太合適你了:https://github.com/Flipboard/FLAnimatedImage
怎樣1句話添加上拉刷新?
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的小對(duì)勾的色彩改成別的色彩?
1
|
_mTableView.tintColor = [UIColor redColor];
|
本來我的statusbar是lightcontent的,結(jié)果用UIImagePickerController會(huì)致使我的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,重寫這個(gè)方法
1
2
3
4
|
- (void) drawPlaceholderInRect:(CGRect)rect {
[[UIColor blueColor] setFill];
[self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment];
}
|
你為何知道這么多奇怪的花招?
去stackoverflow刷問題啊,少年!
能不能只用1個(gè)pan手勢來代替UISwipegesture的各個(gè)方向?
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
- (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;
}
}
|
拉伸圖片的時(shí)候怎樣才能讓圖片不變形?
1. UIImage *image = [[UIImage imageNamed:@"xxx"] stretchableImageWithLeftCapWidth:10 topCapHeight:10];
(剛才有人提示這個(gè)已deprecated了哈,現(xiàn)在的方法叫resizableImageWithCapInsets).
2.以下操作:
怎樣播放GIF的時(shí)候這么卡,有無好點(diǎn)的庫?
FlipBoard出品的太合適你了。https://github.com/Flipboard/FLAnimatedImage
怎樣1句話添加上拉刷新?
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的小對(duì)勾的色彩改成別的色彩?
_mTableView.tintColor = [UIColor redColor];
本來我的statusbar是lightcontent的,結(jié)果用UIImagePickerController會(huì)致使我的statusbar的樣式變成黑色,怎樣辦?
1
2
3
|
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
|
怎樣把我的navigationbar弄成透明的而不是帶模糊的效果?
1
2
|
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;
|
怎樣改變uitextfield placeholder的色彩和位置?
繼承uitextfield,重寫這個(gè)方法
1
2
3
4
|
- (void) drawPlaceholderInRect:(CGRect)rect {
[[UIColor blueColor] setFill];
[self.placeholder drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeTailTruncation alignment:self.textAlignment];
}
|
你為何知道這么多奇怪的花招?
去stackoverflow刷問題啊,少年!
CGfloat和float的區(qū)分?
現(xiàn)在上架的app都要求支持64位系統(tǒng),那末CGFloat和float的區(qū)分就在這里.command+左鍵點(diǎn)擊CGFloat.
1
|
typedef CGFLOAT_TYPE CGFloat;
|
這里可以看到CGFloat是CGFLOAT_TYPE的宏定義,那末這個(gè)又是甚么?
1
2
3
4
5
6
7
8
9
10
11
|
#if defined(__LP64__) && __LP64__
# define CGFLOAT_TYPE double
# define CGFLOAT_IS_DOUBLE 1
# define CGFLOAT_MIN DBL_MIN
# define CGFLOAT_MAX DBL_MAX
#else
# define CGFLOAT_TYPE float
# define CGFLOAT_IS_DOUBLE 0
# define CGFLOAT_MIN FLT_MIN
# define CGFLOAT_MAX FLT_MAX
#endif
|
這段話的意思就是,64位系統(tǒng)下,CGFLOAT是double類型,32位系統(tǒng)下是float類型.CGFloat能夠保證你的代碼在64位系統(tǒng)下也不容易出錯(cuò),所以你的代碼應(yīng)當(dāng)盡可能使用CGFloat.雖然他可能造成1些過剩的消耗.不過能保證安全.
應(yīng)當(dāng)使用FOUNDATION_EXPORT還是#define來定義常量?
1般iOS我們定義常量的方法有兩種,來看下面例子
我的.h文件
1
2
|
FOUNDATION_EXPORT NSString * const kMyConstantString;
FOUNDATION_EXPORT NSString * const kMyConstantString2;
|
.m文件是這樣定義的
1
2
|
NSString * const kMyConstantString = @"Hello";
NSString * const kMyConstantString2 = @"World";
|
還有1種是經(jīng)常使用的#define方法了
1
|
#define kMyConstantString @"Hello"
|
有甚么區(qū)分呢?
使用第1種方法在檢測字符串的值是不是相等的時(shí)候更快.對(duì)第1種你可以直接使用(stringInstance == MyFirstConstant)來比較,而define則使用的是這類.([stringInstance isEqualToString:MyFirstConstant])
哪一個(gè)效力高,不言而喻了.第1種直接比較的是指針地址,而第2個(gè)則是逐一比較字符串的每個(gè)字符是不是相等.
static inline function是干嗎的?
如果你的.m文件需要頻繁調(diào)用1個(gè)函數(shù),可以用static inline來聲明,這相當(dāng)于把函數(shù)體當(dāng)作1個(gè)大號(hào)的宏定義.不過這也不是百分之百有效,到底能不能把函數(shù)體轉(zhuǎn)換為大號(hào)宏定義來用要看編譯器心情,它要是覺得你的方法太復(fù)雜,他就不轉(zhuǎn)了.他直接調(diào)用函數(shù).
類似這類簡單函數(shù)他肯定是樂意的.
1
|
static inline CGRect ScaleRect(CGRect rect, float n)
|
這究竟是甚么鬼?static void *CapturingStillImageContext = &CapturingStillImageContext;
這類聲明方式經(jīng)常使用于kvo,用來當(dāng)作contenxt的key來添加.例如
1
|
[self addObserver:self forKeyPath:@"stillImageOutput.capturingStillImage" options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:CapturingStillImageContext];
|
這類聲明方式可以致使a method to create a unique pointer at compile time.在編譯的時(shí)候創(chuàng)建1個(gè)唯1的指針.由于kvo的時(shí)候context如果不謹(jǐn)慎重復(fù)了,會(huì)產(chǎn)生奇怪的事情.用這類方式可以免.
如何快速定位crash的位置?
選擇Add Exception Breakpoint
這樣如果你的app再crash就會(huì)自動(dòng)定位到那句話.
最快速的提升流暢度的方法?
用instrument找出所有不需要透明但是透明的view,layer.全部弄成不透明的.