Forum Xamarin.iOS

Is there a way to both not slide the page and reduce the width of the master detail menu on ios?

pelinalpppelinalpp Member ✭✭
edited March 23 in Xamarin.iOS

Hi,
I have xamarin forms application on phone. And I try to support on ipad tablet view now. I have MasterDetailPage and I want to use masterdetail as SplitOnPortrait on ipad/tablet devices.
When I use SplitOnPortrait, Master menu takes up a lot of space. It is like following image:

So I wanted to change master detail menu width and I found this solution:
https://stackoverflow.com/questions/48525241/editing-and-using-the-xamarin-forms-source-code/48559533#48559533
https://github.com/lt0526/MasterDetailRendererDemo

It works very good. But when I use SplitOnPortrait, It slides page to right on ios/ipad like following image:

So I can't see right side on my page. I can do it on Android. But I didn't do on ios. Android is like following image:

I want to make same view on iOS. Is there a way to both not slide the page and reduce the width of the master detail menu on ios?

Best Answers

  • ColeXColeX Xamurai
    edited March 25 Accepted Answer

    I notice even set SplitOnPortrait we can also swipe the master detail page , it is supposed to disable swipe gesture and show the complete detail page .

    I've checked your code and see that you copy the code from PhoneMasterDetailRenderer ,actually this renderer is written for Phone, you should use TabletMasterDetailRenderer instead , and modify the master width in ViewDidLayoutSubviews method.

  • ColeXColeX Xamurai
    Accepted Answer

    I comment out some code and try to reduce the width of master page , it works but there is a small issue , you can check my project below .

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Could you please provide a basic , minimum project here to us for test ? We need to reproduce the issue first.

  • pelinalpppelinalpp Member ✭✭
    edited March 24

    I did an example project about my problem. I atteched it.
    I want a view like on android tablet. But ios slides all page to right. So that I can't see right side of page.

    Thank you in advance.
    Example Project:

  • ColeXColeX Member, Xamarin Team Xamurai
    edited March 25 Accepted Answer

    I notice even set SplitOnPortrait we can also swipe the master detail page , it is supposed to disable swipe gesture and show the complete detail page .

    I've checked your code and see that you copy the code from PhoneMasterDetailRenderer ,actually this renderer is written for Phone, you should use TabletMasterDetailRenderer instead , and modify the master width in ViewDidLayoutSubviews method.

  • pelinalpppelinalpp Member ✭✭
    edited March 25

    How can I use two custom renderer for master detail? I thought I must use this for tablet custom renderer:
    [assembly: ExportRenderer(typeof(MasterDetailPage), typeof(MyTabletMasterDetailRenderer), UIUserInterfaceIdiom.Pad)]
    But I inherit MyMasterDetailPageRenderer class from MyPhoneMasterDetailRenderer. How can I use both MyPhoneMasterDetailRenderer and MyTabletMasterDetailRenderer? And I try to use TabletMasterDetailRenderer but it errors for example this usage Forms.IsiOS9OrNewer
    Could you help me please?

  • ColeXColeX Member, Xamarin Team Xamurai

    How can I use both MyPhoneMasterDetailRenderer and MyTabletMasterDetailRenderer?

    Delete MyMasterDetailPageRenderer , use UIUserInterfaceIdiom on different renderer , the app would pick corresponding renderer when running.

    Iphone

    [assembly: ExportRenderer(typeof(MasterDetail), typeof(MyPhoneMasterDetailRenderer), UIUserInterfaceIdiom.Phone)]
    namespace IpadViewMasterDetail.iOS.CustomRenderer
    {
        public class MyPhoneMasterDetailRenderer : UIViewController, IVisualElementRenderer, IEffectControlProvider
        {
    

    Ipad

    [assembly: ExportRenderer(typeof(MasterDetail), typeof(MyTabletMasterDetailRenderer), UIUserInterfaceIdiom.Pad)]
    namespace IpadViewMasterDetail.iOS.CustomRenderer
    {
        public class MyTabletMasterDetailRenderer : UISplitViewController, IVisualElementRenderer, IEffectControlProvider
        {
    

    but it errors for example this usage Forms.IsiOS9OrNewer

    Use UIDevice.CurrentDevice.CheckSystemVersion(9, 0) to replace .

  • pelinalpppelinalpp Member ✭✭
    edited March 27

    Thank you for reply. I will do this and I will give information about this.

  • ColeXColeX Member, Xamarin Team Xamurai

    ok, if you have any problem feel free to ask on the forum .

  • pelinalpppelinalpp Member ✭✭

    Hi @ColeX , I tried. But I have other errors. These is like in following image:

    I look for a solution for example this error:
    'VisualElement' does not contain a definition for 'SendViewInitialized' and no accessible extension method 'SendViewInitialized' accepting a first argument of type 'VisualElement' could be found (are you missing a using directive or an assembly reference?)
    After I found this:
    https://forums.xamarin.com/discussion/177698/visualelement-cannot-find-method-sendviewinitialized
    You said:
    1. I guess SendViewInitialized is built-in method which we can't access .

    I needed to find a solution for my problem. That's why actually I found another solution.
    My solution is: I created a content view for master page (menu view). I use it in master page. And if target idiom is tablet, I prevented opening of master page. I added contentview to right side of my page.
    But I am aware, it is not good solution. I used same view twice. Only I blocked one of them. I must use custom renderer for good solution. But I couldn't it. Is there a way use SendViewInitialized and for other errors?

  • ColeXColeX Member, Xamarin Team Xamurai
    Accepted Answer

    I comment out some code and try to reduce the width of master page , it works but there is a small issue , you can check my project below .

  • pelinalpppelinalpp Member ✭✭

    Yes it works. Thank you very much.

Sign In or Register to comment.