添加AudioToolbox.framework //然后在頭文件中聲明 #import//聲音提示
#import <AudioToolbox/AudioToolbox.h>
// 聲音 振動(dòng)
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//振動(dòng)
AudioServicesPlaySystemSound(1007);//聲音
//注冊(cè)通知 iOS7提供一個(gè)嶄新的推送方法:UIApplicationUserDidTakeScreenshotNotification育叁。只要像往常一樣訂閱即可知道什么時(shí)候截圖了。
// 注意:UIApplicationUserDidTakeScreenshotNotification 將會(huì)在截圖完成之后顯示。現(xiàn)在在截圖截取之前無(wú)法得到通知始锚。
// 希望蘋(píng)果會(huì)在iOS8當(dāng)中增加 UIApplicationUserWillTakeScreenshotNotification沿侈。(只有did, 沒(méi)有will顯然不是蘋(píng)果的風(fēng)格...)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidTakeScreenshot:) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
//人為截屏, 模擬用戶截屏行為, 獲取所截圖片
UIWindow *keyWindow = [[UIApplication sharedApplication]keyWindow];
self.button = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[keyWindow addSubview:self.button];
[self.button addTarget:self action:@selector(buttonAction) forControlEvents:(UIControlEventTouchUpInside)];
-(void)buttonAction
{
self.button .hidden = YES;
_show = NO;
}
show(屬性) 初始NO 截屏后YES 截屏操作后NO 用來(lái)防止連續(xù)多次截屏
#pragma mark - UIApplicationUserDidTakeScreenshotNotification - 檢測(cè)到截屏
- (void)userDidTakeScreenshot:(NSNotification *)notification
{
NSLog(@"檢測(cè)到截屏");
if (!_show) {
_show = YES;
//人為截屏, 模擬用戶截屏行為, 獲取所截圖片
UIImage *image_ = [self imageWithScreenshot];
// UIWindow *keyWindow = [[UIApplication sharedApplication]keyWindow];
self.button .hidden = NO;
[self.button setImage:image_ forState:(UIControlStateNormal)];
}
}
/**
* 返回截取到的圖片
*
* @return UIImage *
*/
- (UIImage *)imageWithScreenshot
{
NSData *imageData = [self dataWithScreenshotInPNGFormat];
return [UIImage imageWithData:imageData];
}
/**
* 截取當(dāng)前屏幕
*
* @return NSData *
*/
- (NSData *)dataWithScreenshotInPNGFormat
{
CGSize imageSize = CGSizeZero;
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsPortrait(orientation)){
imageSize = [UIScreen mainScreen].bounds.size;
} else {
imageSize = CGSizeMake([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
}
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
for (UIWindow *window in [[UIApplication sharedApplication] windows]){
CGContextSaveGState(context);
CGContextTranslateCTM(context, window.center.x, window.center.y);
CGContextConcatCTM(context, window.transform);
CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y);
if (orientation == UIInterfaceOrientationLandscapeLeft){
CGContextRotateCTM(context, M_PI_2);
CGContextTranslateCTM(context, 0, -imageSize.width);
}else if (orientation == UIInterfaceOrientationLandscapeRight){
CGContextRotateCTM(context, -M_PI_2);
CGContextTranslateCTM(context, -imageSize.height, 0);
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
CGContextRotateCTM(context, M_PI);
CGContextTranslateCTM(context, -imageSize.width, -imageSize.height);
}
if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]){
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
}else{
[window.layer renderInContext:context];
}
CGContextRestoreGState(context);
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return UIImagePNGRepresentation(image);
}
//搖一搖的時(shí)候 寫(xiě)在(viewDidLoad){[self becomeFirstResponder];}中 這句話很重要 這是把當(dāng)前VC設(shè)置為第一響應(yīng)者
#pragma mark - 搖一搖
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//檢測(cè)到搖動(dòng)
}
-
(void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent*)event
{
//搖動(dòng)取消
}
-(void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent*)event
{
//搖動(dòng)結(jié)束
if(event.subtype == UIEventSubtypeMotionShake) {
//somethinghappens
}
}
手機(jī)振動(dòng),搖一搖,截屏
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門(mén)涵叮,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人伞插,你說(shuō)我怎么就攤上這事割粮。” “怎么了媚污?”我有些...
- 文/不壞的土叔 我叫張陵舀瓢,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我杠步,道長(zhǎng),這世上最難降的妖魔是什么榜轿? 我笑而不...
- 正文 為了忘掉前任幽歼,我火速辦了婚禮,結(jié)果婚禮上谬盐,老公的妹妹穿的比我還像新娘甸私。我一直安慰自己,他們只是感情好飞傀,可當(dāng)我...
- 文/花漫 我一把揭開(kāi)白布皇型。 她就那樣靜靜地躺著,像睡著了一般砸烦。 火紅的嫁衣襯著肌膚如雪弃鸦。 梳的紋絲不亂的頭發(fā)上,一...
- 那天幢痘,我揣著相機(jī)與錄音唬格,去河邊找鬼。 笑死颜说,一個(gè)胖子當(dāng)著我的面吹牛购岗,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播门粪,決...
- 文/蒼蘭香墨 我猛地睜開(kāi)眼喊积,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了玄妈?” 一聲冷哼從身側(cè)響起乾吻,我...
- 序言:老撾萬(wàn)榮一對(duì)情侶失蹤髓梅,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后溶弟,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體女淑,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年辜御,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了鸭你。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布,位于F島的核電站剖效,受9級(jí)特大地震影響嫉入,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜璧尸,卻給世界環(huán)境...
- 文/蒙蒙 一咒林、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧爷光,春花似錦垫竞、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至徐裸,卻和暖如春遣鼓,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背重贺。 一陣腳步聲響...
- 正文 我出身青樓曾我,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親健民。 傳聞我的和親對(duì)象是個(gè)殘疾皇子抒巢,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 1.搖一搖功能的實(shí)現(xiàn): 在viewDidLoad方法中調(diào)用: 在viewWillAppear方法中調(diào)用: 為了防止...
- 場(chǎng)景由于各種產(chǎn)品需求的變動(dòng)蛉谜,我們?cè)陧?xiàng)目里一般情況下會(huì)用系統(tǒng)的UIAlertController稚晚,當(dāng)然有很多特別的需...
- 寫(xiě)在前面 公司近期讓做一個(gè)錄制屏幕類(lèi)的App客燕,我研究了iOS9新增的Replaykit框架,使用起來(lái)確實(shí)挺簡(jiǎn)單的狰贯,...
- 2017年10月29日 星期日 天氣晴 高中時(shí)有個(gè)同學(xué)在考試時(shí)暈了過(guò)去涵紊,原因大概是低血糖傍妒,考試本就是一件痛...
- 搬進(jìn)一個(gè)新小區(qū)颤练,管理相當(dāng)不好形容,不讓快遞和外賣(mài)進(jìn)驱负,物業(yè)還給我們租戶辦了一個(gè)《外來(lái)人員臨時(shí)出入證》嗦玖。每次外賣(mài)和快遞...