我剛剛開始在iOS開發中,所以忍受着我。我正在爲朋友構建應用程序,其中一項功能就是能夠在Instagram上張貼用戶在應用程序中拍攝的照片。我在同一個控制器中有一個UIImageView
和一個UIView
(vImagePreview
,相機預覽)。會發生的是,當用戶拍攝照片時,UIImageView
被帶到前面,並且靜止圖像的圖像被顯示在UIImageView
中。 UIImageView
(postInstagram)中有一個按鈕觸發調出Instagram菜單的方法。當用戶觸發菜單中的任一事件(在Instagram中打開或取消)時,我希望能夠將原始視圖置於前面。現在我正在使用一個計時器,它確實有效,但它很尷尬。這裏是我的代碼:有沒有什麼方法可以告訴我是否使用UIDocumentInteractionController發生菜單事件?
- (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];
}
非常感謝。這工作。就像我說的,我是一個新手。 :) – Stayshow 2013-04-30 17:22:40