iOS App 开发问题汇总(七)

1.如何设置透明的导航栏并且去掉其底部灰色的分隔线?

A:可以通过设置导航栏的背景图和阴隐图为透明的图片来实现。

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
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    self.translucent = self.navigationController.navigationBar.isTranslucent;
    self.navigationController.navigationBar.translucent = YES;
    
    self.previousImage = [self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault];
    
    UIImage *newImage = [UIImage imageNamed:@"TransparentPixel"];
    [self.navigationController.navigationBar setBackgroundImage:newImage forBarMetrics:UIBarMetricsDefault];
    
    self.previousShadowImage = self.navigationController.navigationBar.shadowImage;
    self.navigationController.navigationBar.shadowImage = newImage;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBar.translucent = self.translucent;
    
    [self.navigationController.navigationBar setBackgroundImage:self.previousImage forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = self.previousShadowImage;
}

Reference:Apple’s sample code Customizing UINavigationBar
Separator between navigation bar and view - iOS 7

继续阅读

iOS App 开发问题汇总(六)

1. The data couldn’t be read because it isn’t in the correct format.

A:项目是2014年开发的,打包导出 Ad-hoc 时报上面的错误,Build Setting > Enable Bitcode > NO 之后再试成功了。

Reference:ipatool fails to build with bitcode (xcode 7.1.1)

2.setNeedsLayout vs. setNeedsUpdateConstraints and layoutIfNeeded vs updateConstraintsIfNeeded

A:

  • If you manipulated constraints directly, call setNeedsLayout.
  • If you changed some conditions (like offsets or smth) which would change constraints in your overridden updateConstraints method (a recommended way to change constraints, btw), call setNeedsUpdateConstraints, and most of the time, setNeedsLayout after that.
  • If you need any of the actions above to have immediate effect—e.g. when your need to learn new frame height after a layout pass—append it with a layoutIfNeeded.

Reference:setNeedsLayout vs. setNeedsUpdateConstraints and layoutIfNeeded vs updateConstraintsIfNeeded

3.父类如何关联子类通过nib初始化的属性?

A: Select xib > Show Utilities > Show The Connection In Inspector > + > Connect to View

继续阅读

Debian 使用笔记

1. Install pear on Debian

A:

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
$ wget http://pear.php.net/go-pear.phar
$ sudo php go-pear.phar

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation base ($prefix)                   : /home/meiliang/pear
 2. Temporary directory for processing            : /tmp/pear/install
 3. Temporary directory for downloads             : /tmp/pear/install
 4. Binaries directory                            : /home/meiliang/pear/bin
 5. PHP code directory ($php_dir)                 : /home/meiliang/pear/share/pear
 6. Documentation directory                       : /home/meiliang/pear/docs
 7. Data directory                                : /home/meiliang/pear/data
 8. User-modifiable configuration files directory : /home/meiliang/pear/cfg
 9. Public Web Files directory                    : /home/meiliang/pear/www
10. System manual pages directory                 : /home/meiliang/pear/man
11. Tests directory                               : /home/meiliang/pear/tests
12. Name of configuration file                    : /home/meiliang/.pearrc

1-12, 'all' or Enter to continue: 1
(Use $prefix as a shortcut for '/home/meiliang/pear', etc.)
Installation base ($prefix) [/home/meiliang/pear] : /usr/local/bin/pear

$ vim .bashrc
# Append the /usr/local/bin/pear directory in the user's home directory onto the PATH environment variable
export PATH=$PATH:/usr/local/bin/pear/bin

// Reload bash configure file
$ source .bashrc

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/bin/pear/bin

// Check wether it works
$ pear version
PEAR Version: 1.10.1
PHP Version: 5.6.17-0+deb8u1
Zend Engine Version: 2.6.0
Running on: Linux Debian 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1 (2015-05-24) x86_64
继续阅读