第一步:根试图成为第一响应者
- (BOOL)canBecomeFirstResponder{
return
YES;
}
开始摇动
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent
*)even
{
NSLog(@"开始摇动手机");
}
结束摇动
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
// UIAlertView *yaoyiyao = [[UIAlertView alloc]initWithTitle:@"提示"
message:@"摇动结束" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
// [yaoyiyao show];
[self getPhoto];
}
获得截图
- (void)getPhoto{
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer
renderInContext:UIGraphicsGetCurrentContext()];
UIImage
*image =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIView
*subView = [[CustomView
alloc]initWithFrame:self.view.frame
withImage:image]; [[UIApplication
sharedApplication].keyWindow
addSubview:subView];
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
}
本文介绍了一个简单的iOS应用功能,通过检测设备摇动来触发截图,并保存到相册。主要内容包括设置视图成为第一响应者,监听并处理摇动事件,以及实现截图功能。
343

被折叠的 条评论
为什么被折叠?



