ios recepies

2014/11/26 11:01
阅读数 63
  • 当你发现使用cornerRadius不管用时,试试view.layer.masksToBounds = YES;Read more.
  • 不像在Android下,iOS里面想搞个点击除了button方便点,其他View着实有点麻烦.点击可以这样做,(以UIImageView为例):
  UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
  singleTap.numberOfTapsRequired = 1;
  [self.logoImageView setUserInteractionEnabled:YES];
  [self.logoImageView addGestureRecognizer:singleTap];
  • 检测屏幕方向变化,7.0+和以前不一样了哦,强迫症患者,看到warning就不爽,所以还是用下面这个吧:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
  • 获取当前屏幕方向
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
if (!UIDeviceOrientationIsLandscape(orientation)) {
    topLayoutGuide = 20.0;
  • 设置StatusBar颜色

You can do this without writing any line of code! Do the following to make the status bar text color white through the whole app On you project plist file: Status bar style: UIStatusBarStyleLightContent View controller-based status bar appearance: NO Status bar is initially hidden: NO

  • 获取StatusBar高度

[UIApplication sharedApplication].statusBarFrame.size.height. But since all sizes are in points, not in pixels, status bar height always equals 20. Update. Seeing this answer being considered helpful, I should elaborate. Status bar height is, indeed, equals 20.0f points except following cases: status bar has been hidden with setStatusBarHidden:withAnimation: method and its height equals 0.0f points; as @Anton here pointed out, during an incoming call outside of Phone application or during sound recording session status bar height equals 40.0f points. There's also a case of status bar affecting the height of your view. Normally, the view's height equals screen dimension for given orientation minus status bar height. However, if you animate status bar (show or hide it) after the view was shown, status bar will change its frame, but the view will not, you'll have to manually resize the view after status bar animation (or during animation since status bar height sets to final value at the start of animation). Update 2. There's also a case of user interface orientation. Status bar does not respect the orientation value, thus status bar height value for portrait mode is [UIApplication sharedApplication].statusBarFrame.size.height (yes, default orientation is always portrait, no matter what your app info.plist says), for landscape - [UIApplication sharedApplication].statusBarFrame.size.width. To determine UI's current orientation when outside of UIViewController and self.interfaceOrietation is not available, use [UIApplication sharedApplication].statusBarOrientation. Update for iOS7. Even though status bar visual style changed, it's still there, its frame still behaves the same. The only interesting find about status bar I got – I share: your UINavigationBar's tiled background will also be tiled to status bar, so you can achieve some interesting design effects or just color your status bar. This, too, won't affect status bar height in any way. Read more


今天在使用CocoaPods来添加AFNetworking时,执行pod install一直卡在了Analyzing dependencies,原因在于当执行这个命令的时候会升级CocoaPods的spec仓库,加一个参数可以省略这一步,然后速度就会提升不少。加参数的命令如下:
pod install --verbose --no-repo-update
pod update --verbose --no-repo-update

2 收藏
0 评论
2 收藏