我才刚刚开始 iOS 开发,所以请多多包涵。我正在为朋友构建一个应用程序,其中一项功能是能够将用户在应用程序中拍摄的照片发布到 Instagram。我在同一个控制器中有一个UIImageView
和一个UIView
(vImagePreview
,相机预览)。发生的情况是,当用户拍照时,UIImageView
被带到前面,静止图片的图像显示在UIImageView
. (postInstagram) 中有一个按钮,UIImageView
用于触发调出 Instagram 菜单的方法。当用户触发菜单中的任一事件(在 Instagram 中打开或取消)时,我希望能够将原始视图置于最前面。现在我正在使用计时器,它确实有效,但很尴尬。这是我的代码:
- (IBAction)postInstagram:(id)sender {
//interactionControllerWithURL:instagramURL
NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/photo.igo"];
//Write image to PNG
[UIImageJPEGRepresentation(self.image, 1.0) writeToFile:savePath atomically:YES];
NSURL *photoURL = [NSURL fileURLWithPath:savePath];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://user?username=USERNAME"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
self.docController = [UIDocumentInteractionController interactionControllerWithURL:photoURL];
self.docController.UTI = @"com.instagram.exclusivegram";
self.docController.annotation = [NSDictionary dictionaryWithObject:@"Insert Caption here" forKey:@"InstagramCaption"];
[self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
timer = [NSTimer scheduledTimerWithTimeInterval: 10.0 target:self selector:@selector(targetMethod:) userInfo:nil repeats: NO];
}
}
-(void) targetMethod:(NSTimer *)timer {
[self.view bringSubviewToFront:self.vImagePreview];
}