iOS一些常用的小知识点
//获取全局的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;
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。