سؤال

أنا مهتم بمعرفة كيف يمكنني تغيير حجم العرض عند الاستخدام UIModalPresentationFormSheet من modalPresentationStyle, ، يبدو أنه يحتوي على حجم ثابت لذلك كنت أتساءل عما إذا كان أي شخص هناك قد تمكن من معالجة وجهة نظر المنبثقة من منظور التحجيم.

لذلك هناك إما UIModalPresentationFormSheet مع حجم العرض الثابت أو وجهات النظر الكاملة وأنا بعد شيء ما بينهما.

هل كانت مفيدة؟

المحلول

MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease]; 

targetController.modalPresentationStyle = UIModalPresentationFormSheet;

targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentModalViewController:targetController animated:YES];

// it is important to do this after presentModalViewController:animated:
targetController.view.superview.bounds = CGRectMake(0, 0, 200, 200);

نصائح أخرى

يمكنك ضبط إطار عرض مشروط بعد تقديمه:

تم اختباره في iOS 5.1 - 6.1 ، باستخدام Xcode 4.62

MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease];
targetController.modalPresentationStyle = UIModalPresentationFormSheet;
targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;  //transition shouldn't matter
[self presentModalViewController:targetController animated:YES];
targetController.view.superview.frame = CGRectMake(0, 0, 200, 200);//it's important to do this after presentModalViewController
targetController.view.superview.center = GPointMake(roundf(self.view.center.x), roundf(self.view.center.y));//self.view assumes the base view is doing the launching, if not you might need self.view.superview.center etc.

تحديث تعمل طريقة عرض وحدة تحكم IOS 6.0 المفضلة أيضًا بشكل صحيح:

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion

في iOS8 والأعمال السابقة:

AboutViewController * _aboutViewController = [[AboutViewController alloc] init];
    _aboutViewController.modalPresentationStyle = UIModalPresentationFormSheet;
    if(IS_IOS8)
    {
        _aboutViewController.preferredContentSize = CGSizeMake(300, 300);
    }
    [self presentViewController:_aboutViewController animated:YES completion:nil];

في ounviewController.M

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];

    if(!IS_IOS8)
    {
        self.view.superview.bounds = CGRectMake(0, 0, 300, 300);
    }
}

IS_IOS8

#define IS_IOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8)

في iOS 8 ، يمكنك أيضًا استخدام UipResentationController الذي يمنحك المزيد من خيارات التخصيص.

بالنسبة لنظام التشغيل iOS 8 ، ما عليك سوى تنفيذ طريقة المندوب (CGSize) PreferDredContentsize على كل وحدة تحكم عرض. يجب أن يحل كل مشكلة الحجم.

فقط لتقديم حل FATOS (واحد رائع) إذا قمت بإنشاء وحدة التحكم في العرض باستخدام ملف .xib بعد initWithNiBName ، يمكنك تخزين إطار العرض:

CGRect myFrame = targetController.view.frame;
...
targetController.view.superview.bounds = myFrame;

ثم استخدمه لمحاسبة الإشراف.

أضع هذا الرمز في وحدة تحكم عرض ورقة النموذج:

-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.view.superview.bounds = CGRectMake(0, 0, 540, 500);  // your size here
}

لاحظ أن الحجم يحدث في وقت مبكر بما فيه الكفاية بحيث تبدو الرسوم المتحركة التقديمية صحيحة.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top