開發中不常用的小功能

1. 去掉BackBarButtonItem的文字

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

2.判斷是否是點擊HOME鍵進入后臺還是點擊了鎖屏鍵鍵入后臺

static void displayStatusChanged(CFNotificationCenterRef center,void *observer,CFStringRef name,const void *object, CFDictionaryRef userInfo){ if (name == CFSTR("com.apple.springboard.lockcomplete")) { [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"kDisplayStatusLocked"]; [[NSUserDefaults standardUserDefaults] synchronize]; } 放進方法: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, displayStatusChanged, CFSTR("com.apple.springboard.lockcomplete"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately); 放進方法:- (void)applicationDidEnterBackground:(UIApplication *)application UIApplicationState state = [[UIApplication sharedApplication] applicationState]; if (state == UIApplicationStateInactive) { NSLog(@"Sent to background by locking screen"); } else if (state == UIApplicationStateBackground) { if (![[NSUserDefaults standardUserDefaults] boolForKey:@"kDisplayStatusLocked"]) { NSLog(@"Sent to background by home button/switching to other app"); } else { NSLog(@"Sent to background by locking screen"); } } 放進方法:- (void)applicationWillEnterForeground:(UIApplication *)application [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"kDisplayStatusLocked"]; [[NSUserDefaults standardUserDefaults] synchronize];

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容