【问题标题】:How to show resized sidebar using SWRevealViewController?如何使用 SWRevealViewController 显示调整大小的侧边栏?
【发布时间】:2014-09-30 07:25:16
【问题描述】:

我在 IOS 应用程序(通用)中使用 SWRevealViewController。我在 iPhone 和 iPad 上都有侧边栏,但我想显示覆盖 90% 屏幕的侧边栏 - 我该怎么做?

【问题讨论】:

  • 它总是覆盖 90% 的视图,你能显示你需要的屏幕截图吗

标签: ios objective-c iphone swift swrevealviewcontroller


【解决方案1】:

打开SWRevealViewController.m文件,然后得到_initDefaultProperties方法。

 - (void)_initDefaultProperties
{

 AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

      float x=(appDelegate.windowWidth)*9/10; //windowWidth=self.window.bounds.size.width;
      float y=x-260;

    _frontViewPosition = FrontViewPositionLeft;
    _rearViewPosition = FrontViewPositionRightMost;
    _rightViewPosition = FrontViewPositionLeft;
    _rearViewRevealWidth = x;
    _rearViewRevealOverdraw = 60.0f+y;
    _rearViewRevealDisplacement = 40.0f+y;
....
}

【讨论】:

  • 如果您使用的是 SWRevealController pod,最好在别处定义此值,而不是编辑 pod 代码。在revealViewController的frontView控制器中,设置rearViewRevealWidth: if self.revealViewController() != nil { self.revealViewController().rearViewRevealWidth = self.view.frame.size.width * 0.80 }
【解决方案2】:

你可以做这样的事情...... 当您拥有 SWRevealViewController 的子类时... 为此问题调用属性并根据需要进行设置... 希望对某人有所帮助...

self.rightViewRevealWidth = [UIScreen mainScreen].bounds.size.width * 0.9;

【讨论】:

    【解决方案3】:

    只需一个 if 语句来确定侧边栏的正确大小。像这样:

    if(device == iPad)
         _rearViewRevealWidth = 600.0f;
    else if(device == iPhone)
         _rearViewRevealWidth = 260.0f;
    

    【讨论】:

    • 是的,我试过了,但我想从可能不在 SWRevealViewController 类中的前视图控制器中使用它。
    【解决方案4】:

    打开SWRevealViewController.m 文件,然后你会得到_initDefaultProperties 方法。在这种方法中,您可以获得侧屏尺寸和位置

    - (void)_initDefaultProperties
    {
    _frontViewPosition = FrontViewPositionLeft;
    _rearViewPosition = FrontViewPositionLeft;
    _rightViewPosition = FrontViewPositionLeft;
    _rearViewRevealWidth = 260.0f;      /// this is the method u change the side bar width
    _rearViewRevealOverdraw = 60.0f;
    _rearViewRevealDisplacement = 40.0f;
    _rightViewRevealWidth = 260.0f;
    _rightViewRevealOverdraw = 60.0f;
    _rightViewRevealDisplacement = 40.0f;
    _bounceBackOnOverdraw = YES;
    _bounceBackOnLeftOverdraw = YES;
    _stableDragOnOverdraw = NO;
    _stableDragOnLeftOverdraw = NO;
    _presentFrontViewHierarchically = NO;
    _quickFlickVelocity = 250.0f;
    _toggleAnimationDuration = 0.25;
    _frontViewShadowRadius = 2.5f;
    _frontViewShadowOffset = CGSizeMake(0.0f, 2.5f);
    _frontViewShadowOpacity = 1.0f;
    _userInteractionStore = YES;
    _animationQueue = [NSMutableArray array];
    _draggableBorderWidth = 0.0f;
    }
    

    【讨论】:

    • 自定义你自己,
    • 谢谢 .. 但是如果我需要在运行时执行它意味着我将确定设备类型并据此显示侧边栏的大小...@Anbu.Kartik跨度>
    • @PremalKhetani - 设备类型指 iPhone 和 iPad
    • @Anbu.Kartik 是的,无论是 iphone 还是 ipad,我都必须相应地显示侧边栏,而无需更改库 (SWRevealViewController)。
    • 对于 iPad 有 UISplitViewController 所以你不需要 SWRevealViewController 。搜索谷歌 UISplitView。
    猜你喜欢
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 2014-07-01
    相关资源
    最近更新 更多