2013-04-30 8 views
0

我剛剛開始在iOS開發中,所以忍受着我。我正在爲朋友構建應用程序,其中一項功能就是能夠在Instagram上張貼用戶在應用程序中拍攝的照片。我在同一個控制器中有一個UIImageView和一個UIViewvImagePreview,相機預覽)。會發生的是,當用戶拍攝照片時,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]; 
} 

回答

0

對不起,我不完全瞭解你的需要。如果我沒有出錯

只需將self.docController.delegate設置爲某個帶有UIDocumentInteractionControllerDelegate的控制器。

然後實現方法和調用targetMethod它:

documentInteractionController:willBeginSendingToApplication: 

如果不是你想要的,只是儘量根據您的需要他人的方法。 http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDocumentInteractionControllerDelegate_protocol/Reference/Reference.html

+0

非常感謝。這工作。就像我說的,我是一個新手。 :) – Stayshow 2013-04-30 17:22:40

相關問題