ios - 使用 RNFrostedSidebar 作为 UIViewController 的一部分

标签 ios objective-c uiviewcontroller

于是在Github上找到了一个非常吸引人的弹出侧边栏动画.但是,我只能将它用作弹出侧边栏(如下面的屏幕截图)。我想将它添加到我的 ViewController 作为左侧栏(如第二个屏幕截图),但还没有找到实现它的方法。有什么建议吗? enter image description here enter image description here 更新:这是我的 viewDidLoad。我尝试了 [self.view addSubview:callout.contentView] 但没有成功

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *images = @[
                        [UIImage imageNamed:@"Home.png"],
                        [UIImage imageNamed:@"Me.png"],
                        [UIImage imageNamed:@"Search.png"],
                        [UIImage imageNamed:@"Trends.png"],
                        [UIImage imageNamed:@"Setting"],
                        ];

    RNFrostedSidebar *callout = [[RNFrostedSidebar alloc] initWithImages:images];
    callout.delegate = self;

    [self.view addSubview:callout.contentView];

    [callout show]; }

这是 RNFrostedSidebar API

RNFrostedSidebar.h RNFrostedSidebar.m

最佳答案

为什么不为此目的使用一个简单的 UIView? RNFrostedSideBar 是满足您需求的过多自定义解决方案。

只需设置足够的自动布局约束并更改您的 sideBar 导出宽度约束常量值(动画)。看看Auto Layout Guide ,它会帮助你。

我将尝试解释我对您的 UIViewController View 内容的看法

+-------------------------+
|sideBar|  contentView    |
|       |                 |
|       |                 |
|       |                 |
|       |                 |
|       |                 |
|       |                 |
+-------------------------+
 <--W-->

W 是连接到您的 @property(弱)IBOutlet NSLayoutConstraint *sideWidthConstraint 的宽度布局约束。 sideBarcontentView 的所有其他约束,例如 LeadingTrailingTopBottom 应设置为零。注意 View 之间的约束。它也必须为零:

+---------------------------+
| sideBar |-0-| contentView |

当你需要改变你的sideBar宽度(和减少其中一个contentView)时,只需改变sideWidthConstraint常量值:

[UIView animateWithDuration:0.3 animations:^{
  self.sideWidthConstraint.constant = expanded ? 50 : 0; // expanded - YES of NO
  [self.view layoutIfNeeded];
}];

关于ios - 使用 RNFrostedSidebar 作为 UIViewController 的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27373667/

相关文章:

iphone - 如何强制 UIButton 始终在顶部

ios - 强 block 捕获 'self'

iphone - 电子邮件在 ShareKit 中不起作用且没有错误

ios - 使用 react 性 cocoa 处理链接请求的最佳实践

ios - 如何返回当前 View Controller ?

ios - -[UIViewController tableView :numberOfRowsInSection:]: unrecognized selector sent to instance

ios - 作为 iOS 开发人员我应该使用什么 TestFlight

ios - ScrollView 不垂直滚动

objective-c - 你能通过 dismissModalViewControllerAnimated : or do you need a segue for the return journey? 返回数据吗

ios - 从 TabBarController 呈现导航 Controller