標籤:
//擷取全域的Delegate對象,這樣我們可以調用這個對象裡的方法和變數
[[UIApplication sharedApplication] delegate];
//獲得程式的主Bundle
NSBundle *bundle = [NSBundle mainBundle];
/*
在程式中播放聲音
1.添加AudioToolbox架構
*/
NSString *path = [bundle pathForResource:@"soundFileName" ofType:@"wav"];
SystemSoundID soundId;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)([NSURL URLWithString:path]), &soundId);
AudioServicesPlayAlertSound(soundId);
//捕捉程式關閉或者進入後台事件
UIApplication *application = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:application];
}
- (void)applicationWillResignActive:(NSNotification *)noti{
}
#pragma mark -- 擷取截屏
- (UIImage *)getScreenShot{
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
iOS一些常用的小知識點