2014-07-18 12 views
15

मैं एक UIViewController iPad पर एक मॉडल UIModalPresentationFormSheet का उपयोग कर के रूप में प्रस्तुत आकार बदलने के लिए कोशिश कर रहा हूँ, और हालांकि मुझे मिल गया यह < पर काम कर = iOS 7, मैं नहीं iOS 8iOS पर UIModalPresentationFormSheet का आकार बदलना 8

उत्तर

30

आईओएस 8 के लिए आपको "पसंदीदा सामग्री" संपत्ति सेट करना होगा, लेकिन आईओएस 7 और पुराने के लिए आपको superview.frame प्रॉपर्टी सेट करनी होगी।

उदाहरण कोड:

UIViewController* modalController = [[UIViewController alloc]init]; 
modalController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
modalController.modalPresentationStyle = UIModalPresentationFormSheet; 

CGPoint frameSize = CGPointMake([[UIScreen mainScreen] bounds].size.width*0.95f, [[UIScreen mainScreen] bounds].size.height*0.95f); 
CGRect screenRect = [[UIScreen mainScreen] bounds]; 
CGFloat screenWidth = screenRect.size.width; 
CGFloat screenHeight = screenRect.size.height; 

// Resizing for iOS 8 
modalController.preferredContentSize = CGSizeMake(frameSize.x, frameSize.y); 
// Resizing for <= iOS 7 
modalController.view.superview.frame = CGRectMake((screenWidth - frameSize.x)/2, (screenHeight - frameSize.y)/2, frameSize.x, frameSize.y); 

UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; 
[vc presentViewController:modalController animated:YES completion:nil]; 
+0

मीठा, यह चाल है! –

+0

कभी-कभी यह केवल तभी काम करता है जब आप आकार बदलने के बाद * दृश्य नियंत्रक – Micho

+0

प्रस्तुत करते हैं IOS7 के लिए XCode5 के साथ काम नहीं करते हैं। XCode6 – JerryZhou

9

पर इस पर निर्भर करता है सकते हैं यदि आप UIPopoverPresentationController या UIPresentationController का उपयोग कर रहे हैं। आप "पसंदीदा सामग्री" संपत्ति को अपनी नई सामग्री आकार ("ContentSizeForViewInPopover" संपत्ति को आईओएस 8 में बहिष्कृत करने के लिए सेट करने का प्रयास कर सकते हैं)।

+0

ऐसा किया आप के लिए काम करता हूं? मुझे बताएं क्या आपको किसी भी तरह की मदद की ज़रूरत है। – kevinl

+1

मैंने अंततः एक कस्टम व्यू बनाकर एक कामकाज किया। मैं वैसे भी आपके जवाब को वैध मानने वाला हूं। धन्यवाद! –

6

एक UIViewController के दृश्य आकार बदलने के लिए, जब यह पहले से ही UIModalPresentationFormSheet मोडल प्रस्तुति शैली के साथ प्रस्तुत किया और दिख रहा है है, iOS के लिए उपयोग करें 8:

self.preferredContentSize = CGSizeMake(width, height); 

[UIView animateWithDuration:0.25 animations:^{ 
    [self.presentationController.containerView setNeedsLayout]; 
    [self.presentationController.containerView layoutIfNeeded]; 
}]; 
संबंधित मुद्दे