于是在Github上找到了一个非常吸引人的弹出侧边栏动画.但是,我只能将它用作弹出侧边栏(如下面的屏幕截图)。我想将它添加到我的 ViewController 作为左侧栏(如第二个屏幕截图),但还没有找到实现它的方法。有什么建议吗?
更新:这是我的 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
最佳答案
为什么不为此目的使用一个简单的 UIView? RNFrostedSideBar
是满足您需求的过多自定义解决方案。
只需设置足够的自动布局约束并更改您的 sideBar
导出宽度约束常量值(动画)。看看Auto Layout Guide ,它会帮助你。
我将尝试解释我对您的 UIViewController View 内容的看法
+-------------------------+
|sideBar| contentView |
| | |
| | |
| | |
| | |
| | |
| | |
+-------------------------+
<--W-->
W
是连接到您的 @property(弱)IBOutlet NSLayoutConstraint *sideWidthConstraint
的宽度布局约束。 sideBar
和 contentView
的所有其他约束,例如 Leading
、Trailing
、Top
、 Bottom
应设置为零。注意 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/