[英]Modal UIViewController appears black after using UIActivityController
閱讀底部的我的編輯
在我的應用程序中,我有一個UIViewController
,它經常顯示一個模式UIViewController
。 這發生沒有問題
-(void)flash
{
[self performSegueWithIdentifier:SEGUE_IDENTIFIER sender:self];
}
-(void)stopFlash
{
[self dismissViewControllerAnimated:YES completion:nil]
}
但是,當用戶點擊共享按鈕時,關閉共享對話框(只需取消或執行其他操作),並且應該再次顯示第一個模式UIViewController
,它只會顯示黑屏。 但是實例化了正確的模式UIViewController
,我可以在NSLogs
看到它。 當點擊共享按鈕時,我使用以下操作:
- (IBAction)share:(id)sender
{
self.shareButton.hidden = YES;
[self.buttonActivity startAnimating];
dispatch_queue_t queue = dispatch_queue_create("background", NULL);
dispatch_async(queue, ^{
NSURL *url = APP_URL;
NSString *message = SHARE_MESSAGE;
NSArray *activities = [NSArray arrayWithObjects:message, url, nil];
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:activities applicationActivities:nil];
activity.excludedActivityTypes = @[UIActivityTypeCopyToPasteboard, UIActivityTypeAddToReadingList];
};
self.shareController = activity;
dispatch_async(dispatch_get_main_queue(), ^{
[self.buttonActivity stopAnimating];
self.shareButton.hidden = NO;
[self presentViewController:self.shareController animated:YES completion:nil];
});
});
}
編輯 :經過更多研究后,我發現問題出在UIColor
類別中,但我仍然無法修復它。 我有一種方法的UIColor上的Category random
:
+(UIColor *)randomColor
{
CGFloat hue = ( arc4random() % 256 / 256.0 );
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5;
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5;
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
NSLog(@"color: %@", color);
return color;
}
此方法通常只返回隨機顏色,該顏色在UIView
上設置為背景。 由於某種原因,在我第一次打開UIActivityViewController``randomColor
的情況下, UIActivityViewController``randomColor
只返回nil。 實際上,該方法中的NSLog
甚至沒有執行,因此甚至沒有調用randomColor方法。 為什么? 太瘋狂了。
謝謝你的幫助。
找到了解決方案:UIActivityViewController在UIColor上定義了一個私有randomColor方法,該方法重寫了我的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.