iOS FAQ Summary

1.NSTimer中方法如:

scheduledTimerWithTimeInterval:target: selector:userInfo:repeats:

注意通过selector调用方法,传递参数时(userInfo),需要通过[XXX userInfo]来接收。

eg:

timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(test:) userInfo:@3 repeats:NO];

- (void)test:(NSTimer*)number {        

         NSLog(@"%@",[number userInfo]);

}

2.同时按下两个按钮,限制只触发一个按钮事件。

[myButton setExclusiveTouch:YES];

参考文档:ios - objective c how to set exclusive touch for all UIbuttons on the whole app - Stack Overflow

3.xib布局时,frame的变化。

viewWillAppear:

Notifies the view controller that its view is about to be added to a view hierarchy.

viewDidAppear:

Notifies the view controller that its view was added to a view hierarchy.

As a result the frames of the subviews aren't yet set in theviewWillAppear:

The appropriate method tomodify your UI before the view is presented to the screenis:

viewDidLayoutSubviews

Notifies the view controller that its view just laid out its subviews.

参考文档:

objective c - Unable to set frame correctly before viewDidAppear - Stack Overflow

ios - UIViewController returns invalid frame? - Stack Overflow

4.xcode6创建的工程在ios7下运行,出现显示不全,上下两条黑边的问题,在iOS8能正常显示。

Xcode6中模版工程默认使用LaunchScreen.xib,如果要支持iOS7,还是得使用LaunchImage。

启用过程:在target的general设置中找到App Icons and Launch Images, 然后点击Use Asset Catalog,接下来按提示操作就可以了。

Configuring Your Xcode Project for Distribution

5.button设置image,设置image属性显示实际大小,backgroundImage会随着按钮的size改变。就好比一个view上有一个imageView,修改view的大小,imageview是不会变的。

6.打印fontNames

//打印所有fontName

NSArray*familyNames = [UIFontfamilyNames];

for(NSString*familyNameinfamilyNames )

{

NSArray*fontNames = [UIFontfontNamesForFamilyName:familyName];

for(NSString*fontNameinfontNames )

{

printf("\tFont: %s \n", [fontNameUTF8String] );

}

}

7.计算运行时间(kissGod)

#define TICK  NSDate *startTime = [NSDate date]

#define TOCK  NSLog(@"Time: %f", -[startTime timeIntervalSinceNow])

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

TICK

//do your work here

TOCK

8.icon 有黑边问题

提交方形图片,系统会自动圆角化处理。如果你的图片资源已经切好圆角,会因为不够精确(与系统不是100%一致)而产生黑色的毛边。

你可能感兴趣的:(iOS FAQ Summary)