CooperRS / RMActionController

This is an iOS control for presenting any UIView in an UIAlertController like manner
MIT License
539 stars 59 forks source link

Disappeared title and message when using pure RMActionController without inheritance. #7

Closed metasmile closed 9 years ago

metasmile commented 9 years ago

hello, CooperRS :) I can't show title and message at the top of controller when using basic RMActionController. It looks like dependent on layout constraints such as 'translatesAutoresizingMaskIntoConstraints' and entire VC's height. Must I write below codes for auto layout every inherited uiviewcontroller to show title and message?

...
actionController.contentView.translatesAutoresizingMaskIntoConstraints = NO;
...
NSDictionary *bindings = @{@"contentView": actionController.contentView};
        [actionController.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[contentView(>=300)]" options:0 metrics:nil views:bindings]];
        [actionController.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[contentView(140)]" options:0 metrics:nil views:bindings]];

i wrote like below (to add a MPVolumeView)

RMActionController *actionController = [RMActionController actionControllerWithStyle:RMActionControllerStyleBlack
                                                                                       title:@"Test"
                                                                                     message:@"This is a test action controller.\nPlease tap 'Select' or 'Cancel'."
                                                                                selectAction:nil
                                                                             andCancelAction:nil];

        [actionController addAction:[RMAction actionWithTitle:@"Done" style:RMActionStyleDone andHandler:^(RMActionController *controller) {

        }]];
        actionController.disableBouncingEffects = YES;
        actionController.disableBlurEffectsForBackgroundView = YES;

        //On the iPad we want to show the map action controller within a popover. Fortunately, we can use iOS 8 API for this! :)
        //(Of course only if we are running on iOS 8 or later)
        if([actionController respondsToSelector:@selector(popoverPresentationController)] && [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
            //First we set the modal presentation style to the popover style
            actionController.modalPresentationStyle = UIModalPresentationPopover;
            //Then we tell the popover presentation controller, where the popover should appear
//            actionController.popoverPresentationController.sourceView = self.tableView;
//            actionController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
        }

        //Now just present the date selection controller using the standard iOS presentation method
        actionController.contentView = [[UIView alloc] initWithFrame:CGRectZero];
        actionController.contentView.translatesAutoresizingMaskIntoConstraints = NO;

        MPVolumeView * volumeView = [[MPVolumeView alloc] initWithSize:CGSizeMake(0,50)];
        volumeView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [actionController.contentView addSubview:volumeView];

/*
        NSDictionary *bindings = @{@"contentView": actionController.contentView};
        [actionController.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[contentView(>=300)]" options:0 metrics:nil views:bindings]];
        [actionController.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[contentView(140)]" options:0 metrics:nil views:bindings]];
*/

        [[UIApplication sharedApplication].keyWindow.rootViewController  presentViewController:actionController animated:YES completion:nil];

and i hope to write like this (case for iphone only - just set contentview. and the end):

RMActionController *actionController = [RMActionController actionControllerWithStyle:RMActionControllerStyleBlack
                                                                                       title:@"Test"
                                                                                     message:@"This is a test action controller.\nPlease tap 'Select' or 'Cancel'."
                                                                                selectAction:nil
                                                                             andCancelAction:nil];

        [actionController addAction:[RMAction actionWithTitle:@"Done" style:RMActionStyleDone andHandler:^(RMActionController *controller) {

        }]];

        actionController.disableBouncingEffects = YES;
        actionController.disableBlurEffectsForBackgroundView = YES;

// just set contentview. and the end.
        actionController.contentView = [[MPVolumeView alloc] initWithSize:CGSizeMake(0,50)];
        actionController.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

        [[UIApplication sharedApplication].keyWindow.rootViewController  presentViewController:actionController animated:YES completion:nil];
CooperRS commented 9 years ago

Hi,

Actually, you have to set the height of the custom content view using auto layout.

And this is why subclassing RMActionController is recommended. This way you do not have to write the code for adding the content view every time you present your subclass of RMActionController.

Hope I could help. If you have any more questions feel free to ask :)

Best regards, Roland

metasmile commented 9 years ago

yep, In fact, layout calculation via codes(but via very structural methods) is probably just my personal preference.(because I hate current ios auto layout system and customizing pattern..) your way is the right way, but currently i think there may be a better way to use simply. so someday I'll make a fork and modify something when I get time. :)

Anyway, once I'm using well. Roland thanks for your reply and good work.