第一步:根试图成为第一响应者
- (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);
}