uiviewcontroller of smaller size











up vote
1
down vote

favorite












I am new to iOS development and am trying to make a custom toast by using UIViewController of smaller size and presenting it modally. I want that when the view controller is presented, the background screen remains responsive (clickable/scrollable) but at the moment, the background screen becomes unresponsive until the presented view controller is dismissed. Any help in the right direction would be appreciated.
Thanks!



Edit 1:
This is the function inside NotificationToastViewController which is called to show the toast.



class func popup(with presentable: NotificationToastPresentable, onViewDidAppear: (() -> ())? = nil, onDismiss: ((CloseStatus) -> ())? = nil, bool1: Bool = false, bool2: Bool = false) {
let popupViewController = NotificationToastViewController()
popupViewController.modalTransitionStyle = .crossDissolve
popupViewController.modalPresentationStyle = .overCurrentContext
let _ = popupViewController.view
popupViewController.configureWith(presentable)
popupViewController.onViewDidAppear = onViewDidAppear
popupViewController.onDismiss = onDismiss

if bool1 {
popupViewController.statusLabelConstraintToBottom?.constant = 12.0
popupViewController.statusLabelLeadingConstraint?.constant = 10.0
popupViewController.statusLabelConstraintWithIcon?.isActive = false
} else {
popupViewController.statusLabelConstraintToBottom?.isActive = false
popupViewController.statusLabelLeadingConstraint?.isActive = false
}

if bool2 {
popupViewController.heightConstrainOfCtaButton?.isActive = false
}
UIApplication.shared.topMostViewController()?.present(popupViewController, animated: true)
}


This is the view hierarchy in the xib:
This is the view hierarchy in the xib:










share|improve this question




















  • 1




    It is easy to add a custom UIView as toast to the view of UIViewController directly rather presenting it in the way modally. Even you can make it as reusable and can add it where ever you want by setting up the frame of the view.
    – Sateesh
    Nov 10 at 13:08












  • If you don't like view you can add container views to any viewcontroller. But for the sake of simplicity and reusability adding view is good choice .
    – guru
    Nov 10 at 13:27












  • @Sateesh How do you show a custom uiview as toast? I have created an xib for the custom uiview. I feel that the reason for it blocking might be that i am using safeview to add constraints for the custom uiview and that might be the reason it completely blocks the ui since safe view occupies the entire screen?
    – Priyanshu Goyal
    2 days ago










  • @Priyanshu, can you please share the code what you have tried so far, if you don't mind ?
    – Sateesh
    2 days ago










  • @Sateesh please check the edit.
    – Priyanshu Goyal
    2 days ago















up vote
1
down vote

favorite












I am new to iOS development and am trying to make a custom toast by using UIViewController of smaller size and presenting it modally. I want that when the view controller is presented, the background screen remains responsive (clickable/scrollable) but at the moment, the background screen becomes unresponsive until the presented view controller is dismissed. Any help in the right direction would be appreciated.
Thanks!



Edit 1:
This is the function inside NotificationToastViewController which is called to show the toast.



class func popup(with presentable: NotificationToastPresentable, onViewDidAppear: (() -> ())? = nil, onDismiss: ((CloseStatus) -> ())? = nil, bool1: Bool = false, bool2: Bool = false) {
let popupViewController = NotificationToastViewController()
popupViewController.modalTransitionStyle = .crossDissolve
popupViewController.modalPresentationStyle = .overCurrentContext
let _ = popupViewController.view
popupViewController.configureWith(presentable)
popupViewController.onViewDidAppear = onViewDidAppear
popupViewController.onDismiss = onDismiss

if bool1 {
popupViewController.statusLabelConstraintToBottom?.constant = 12.0
popupViewController.statusLabelLeadingConstraint?.constant = 10.0
popupViewController.statusLabelConstraintWithIcon?.isActive = false
} else {
popupViewController.statusLabelConstraintToBottom?.isActive = false
popupViewController.statusLabelLeadingConstraint?.isActive = false
}

if bool2 {
popupViewController.heightConstrainOfCtaButton?.isActive = false
}
UIApplication.shared.topMostViewController()?.present(popupViewController, animated: true)
}


This is the view hierarchy in the xib:
This is the view hierarchy in the xib:










share|improve this question




















  • 1




    It is easy to add a custom UIView as toast to the view of UIViewController directly rather presenting it in the way modally. Even you can make it as reusable and can add it where ever you want by setting up the frame of the view.
    – Sateesh
    Nov 10 at 13:08












  • If you don't like view you can add container views to any viewcontroller. But for the sake of simplicity and reusability adding view is good choice .
    – guru
    Nov 10 at 13:27












  • @Sateesh How do you show a custom uiview as toast? I have created an xib for the custom uiview. I feel that the reason for it blocking might be that i am using safeview to add constraints for the custom uiview and that might be the reason it completely blocks the ui since safe view occupies the entire screen?
    – Priyanshu Goyal
    2 days ago










  • @Priyanshu, can you please share the code what you have tried so far, if you don't mind ?
    – Sateesh
    2 days ago










  • @Sateesh please check the edit.
    – Priyanshu Goyal
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am new to iOS development and am trying to make a custom toast by using UIViewController of smaller size and presenting it modally. I want that when the view controller is presented, the background screen remains responsive (clickable/scrollable) but at the moment, the background screen becomes unresponsive until the presented view controller is dismissed. Any help in the right direction would be appreciated.
Thanks!



Edit 1:
This is the function inside NotificationToastViewController which is called to show the toast.



class func popup(with presentable: NotificationToastPresentable, onViewDidAppear: (() -> ())? = nil, onDismiss: ((CloseStatus) -> ())? = nil, bool1: Bool = false, bool2: Bool = false) {
let popupViewController = NotificationToastViewController()
popupViewController.modalTransitionStyle = .crossDissolve
popupViewController.modalPresentationStyle = .overCurrentContext
let _ = popupViewController.view
popupViewController.configureWith(presentable)
popupViewController.onViewDidAppear = onViewDidAppear
popupViewController.onDismiss = onDismiss

if bool1 {
popupViewController.statusLabelConstraintToBottom?.constant = 12.0
popupViewController.statusLabelLeadingConstraint?.constant = 10.0
popupViewController.statusLabelConstraintWithIcon?.isActive = false
} else {
popupViewController.statusLabelConstraintToBottom?.isActive = false
popupViewController.statusLabelLeadingConstraint?.isActive = false
}

if bool2 {
popupViewController.heightConstrainOfCtaButton?.isActive = false
}
UIApplication.shared.topMostViewController()?.present(popupViewController, animated: true)
}


This is the view hierarchy in the xib:
This is the view hierarchy in the xib:










share|improve this question















I am new to iOS development and am trying to make a custom toast by using UIViewController of smaller size and presenting it modally. I want that when the view controller is presented, the background screen remains responsive (clickable/scrollable) but at the moment, the background screen becomes unresponsive until the presented view controller is dismissed. Any help in the right direction would be appreciated.
Thanks!



Edit 1:
This is the function inside NotificationToastViewController which is called to show the toast.



class func popup(with presentable: NotificationToastPresentable, onViewDidAppear: (() -> ())? = nil, onDismiss: ((CloseStatus) -> ())? = nil, bool1: Bool = false, bool2: Bool = false) {
let popupViewController = NotificationToastViewController()
popupViewController.modalTransitionStyle = .crossDissolve
popupViewController.modalPresentationStyle = .overCurrentContext
let _ = popupViewController.view
popupViewController.configureWith(presentable)
popupViewController.onViewDidAppear = onViewDidAppear
popupViewController.onDismiss = onDismiss

if bool1 {
popupViewController.statusLabelConstraintToBottom?.constant = 12.0
popupViewController.statusLabelLeadingConstraint?.constant = 10.0
popupViewController.statusLabelConstraintWithIcon?.isActive = false
} else {
popupViewController.statusLabelConstraintToBottom?.isActive = false
popupViewController.statusLabelLeadingConstraint?.isActive = false
}

if bool2 {
popupViewController.heightConstrainOfCtaButton?.isActive = false
}
UIApplication.shared.topMostViewController()?.present(popupViewController, animated: true)
}


This is the view hierarchy in the xib:
This is the view hierarchy in the xib:







ios swift uiviewcontroller toast presentviewcontroller






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked Nov 10 at 12:07









Priyanshu Goyal

388




388








  • 1




    It is easy to add a custom UIView as toast to the view of UIViewController directly rather presenting it in the way modally. Even you can make it as reusable and can add it where ever you want by setting up the frame of the view.
    – Sateesh
    Nov 10 at 13:08












  • If you don't like view you can add container views to any viewcontroller. But for the sake of simplicity and reusability adding view is good choice .
    – guru
    Nov 10 at 13:27












  • @Sateesh How do you show a custom uiview as toast? I have created an xib for the custom uiview. I feel that the reason for it blocking might be that i am using safeview to add constraints for the custom uiview and that might be the reason it completely blocks the ui since safe view occupies the entire screen?
    – Priyanshu Goyal
    2 days ago










  • @Priyanshu, can you please share the code what you have tried so far, if you don't mind ?
    – Sateesh
    2 days ago










  • @Sateesh please check the edit.
    – Priyanshu Goyal
    2 days ago














  • 1




    It is easy to add a custom UIView as toast to the view of UIViewController directly rather presenting it in the way modally. Even you can make it as reusable and can add it where ever you want by setting up the frame of the view.
    – Sateesh
    Nov 10 at 13:08












  • If you don't like view you can add container views to any viewcontroller. But for the sake of simplicity and reusability adding view is good choice .
    – guru
    Nov 10 at 13:27












  • @Sateesh How do you show a custom uiview as toast? I have created an xib for the custom uiview. I feel that the reason for it blocking might be that i am using safeview to add constraints for the custom uiview and that might be the reason it completely blocks the ui since safe view occupies the entire screen?
    – Priyanshu Goyal
    2 days ago










  • @Priyanshu, can you please share the code what you have tried so far, if you don't mind ?
    – Sateesh
    2 days ago










  • @Sateesh please check the edit.
    – Priyanshu Goyal
    2 days ago








1




1




It is easy to add a custom UIView as toast to the view of UIViewController directly rather presenting it in the way modally. Even you can make it as reusable and can add it where ever you want by setting up the frame of the view.
– Sateesh
Nov 10 at 13:08






It is easy to add a custom UIView as toast to the view of UIViewController directly rather presenting it in the way modally. Even you can make it as reusable and can add it where ever you want by setting up the frame of the view.
– Sateesh
Nov 10 at 13:08














If you don't like view you can add container views to any viewcontroller. But for the sake of simplicity and reusability adding view is good choice .
– guru
Nov 10 at 13:27






If you don't like view you can add container views to any viewcontroller. But for the sake of simplicity and reusability adding view is good choice .
– guru
Nov 10 at 13:27














@Sateesh How do you show a custom uiview as toast? I have created an xib for the custom uiview. I feel that the reason for it blocking might be that i am using safeview to add constraints for the custom uiview and that might be the reason it completely blocks the ui since safe view occupies the entire screen?
– Priyanshu Goyal
2 days ago




@Sateesh How do you show a custom uiview as toast? I have created an xib for the custom uiview. I feel that the reason for it blocking might be that i am using safeview to add constraints for the custom uiview and that might be the reason it completely blocks the ui since safe view occupies the entire screen?
– Priyanshu Goyal
2 days ago












@Priyanshu, can you please share the code what you have tried so far, if you don't mind ?
– Sateesh
2 days ago




@Priyanshu, can you please share the code what you have tried so far, if you don't mind ?
– Sateesh
2 days ago












@Sateesh please check the edit.
– Priyanshu Goyal
2 days ago




@Sateesh please check the edit.
– Priyanshu Goyal
2 days ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













You can do something of this sort:



var vc = SecondController()
self.addChild(vc)
self.view.addSubview(vc.view!)
vc.view.translatesAutoresizingMaskIntoConstraints = false
vc.view.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 200).isActive = true
vc.view.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 300).isActive = true
vc.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0).isActive = true
vc.view.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: 0).isActive = true


Where SecondViewController is another ViewController class, which you have to add as a child Controller to your home controller and then set the constraints of the second controller's view. I believe the result of such an implementation is what you are trying to achieve.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238787%2fuiviewcontroller-of-smaller-size%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    You can do something of this sort:



    var vc = SecondController()
    self.addChild(vc)
    self.view.addSubview(vc.view!)
    vc.view.translatesAutoresizingMaskIntoConstraints = false
    vc.view.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 200).isActive = true
    vc.view.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 300).isActive = true
    vc.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0).isActive = true
    vc.view.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: 0).isActive = true


    Where SecondViewController is another ViewController class, which you have to add as a child Controller to your home controller and then set the constraints of the second controller's view. I believe the result of such an implementation is what you are trying to achieve.






    share|improve this answer

























      up vote
      0
      down vote













      You can do something of this sort:



      var vc = SecondController()
      self.addChild(vc)
      self.view.addSubview(vc.view!)
      vc.view.translatesAutoresizingMaskIntoConstraints = false
      vc.view.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 200).isActive = true
      vc.view.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 300).isActive = true
      vc.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0).isActive = true
      vc.view.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: 0).isActive = true


      Where SecondViewController is another ViewController class, which you have to add as a child Controller to your home controller and then set the constraints of the second controller's view. I believe the result of such an implementation is what you are trying to achieve.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        You can do something of this sort:



        var vc = SecondController()
        self.addChild(vc)
        self.view.addSubview(vc.view!)
        vc.view.translatesAutoresizingMaskIntoConstraints = false
        vc.view.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 200).isActive = true
        vc.view.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 300).isActive = true
        vc.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0).isActive = true
        vc.view.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: 0).isActive = true


        Where SecondViewController is another ViewController class, which you have to add as a child Controller to your home controller and then set the constraints of the second controller's view. I believe the result of such an implementation is what you are trying to achieve.






        share|improve this answer












        You can do something of this sort:



        var vc = SecondController()
        self.addChild(vc)
        self.view.addSubview(vc.view!)
        vc.view.translatesAutoresizingMaskIntoConstraints = false
        vc.view.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 200).isActive = true
        vc.view.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 300).isActive = true
        vc.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0).isActive = true
        vc.view.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: 0).isActive = true


        Where SecondViewController is another ViewController class, which you have to add as a child Controller to your home controller and then set the constraints of the second controller's view. I believe the result of such an implementation is what you are trying to achieve.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 13:15









        SWAT

        551311




        551311






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238787%2fuiviewcontroller-of-smaller-size%23new-answer', 'question_page');
            }
            );

            Post as a guest