【发布时间】:2015-04-19 03:32:04
【问题描述】:
通常,如果使用 SWRevealViewController,前视图会完全覆盖后视图,而后视图只有在执行某些操作(滑动、点击等)时才可见。我的要求是,当视图加载和用户向后滑动时,后视图至少应该始终可见。我尝试修改frontView的框架来实现这一点,但我没有看到任何效果。
我把帧更新帧代码放在一个方法里:
-(void)updateFrontViewControllerFrameWithPadding:(BOOL)bProvidePadding
{
if (!bProvidePadding) {
CGRect frontViewControllerFrame = self.frontViewController.view.bounds;
CGFloat xOrigin = self.view.bounds.origin.x;
CGFloat nWidth = self.view.bounds.size.width;
frontViewControllerFrame.origin.x = xOrigin;
frontViewControllerFrame.size.width = nWidth;
self.frontViewController.view.frame = frontViewControllerFrame;
_frontViewShadowColor = [UIColor blackColor];
[_contentView reloadShadow];
}
else {
CGFloat nPadding = 0.0f;
if ([IILUtility targetDevice] == UIUserInterfaceIdiomPad) {
_rearViewRevealWidthIpad = 20.0f;
nPadding = _rearViewRevealWidthIpad;
}
else {
_rearViewRevealWidthIphone = 15.0f;
nPadding = _rearViewRevealWidthIphone;
}
CGRect revealViewBounds = self.view.bounds;
CGFloat frontViewXPos = revealViewBounds.origin.x + nPadding;
CGFloat frontViewWidth = revealViewBounds.size.width - nPadding;
CGRect frontViewFrame = self.frontViewController.view.frame;
frontViewFrame.origin.x = frontViewXPos;
frontViewFrame.size.width = frontViewWidth;
self.frontViewController.view.frame = frontViewFrame;
_frontViewShadowColor = [UIColor colorWithWhite:0.5
alpha:0.5];
[_contentView reloadShadow];
//reset rearViewRevealWidth
[self resetRearViewRevealWidth];
}
}
此方法从 viewWillLayoutSubviews 方法调用,providePadding 参数为 TRUE。此方法还需要从 SWRevealViewController 中已处理平移和点击手势的位置调用。
这是滑动时视图的外观:
【问题讨论】:
-
由于缩小了前视图的框架,边框占用了所有空间。如何防止这种情况发生?当我慢慢滑动前视图时,我注意到后视图被加载,好像它的宽度随着滑动动作的执行而增加。是这样吗?如果是这样,后视图的初始宽度是否等于零?如何将其设置为不同的值?
标签: ios objective-c swrevealviewcontroller