通常情况下,如果使用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中已经处理了平移和点击手势的位置调用。
滑动时视图的外观如下:
答案 0 :(得分:0)
这是帧大小调整问题的解决方案:
-(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];
//There is a catch here. The shadow for _frontView is different from that of self.frontViewController.view
//If we do not modify the shadow for self.frontViewController.view then it overlaps with
// the shadow of _frontView. This is generally not a problem in the case when the rear view is in focus and the
//front view is toggled to the right. But if we need the front view to be shifted slighlty to the right even when
//its position is FrontViewPositionLeft, it is important to manage the shadow of self.frontViewController.view
//otherwise the shadow takes up width equal to the padding we have provided.
CALayer *frontViewLayer = self.frontViewController.view.layer;
frontViewLayer.shadowColor = [UIColor colorWithWhite:0.8f
alpha:0.0f].CGColor;
frontViewLayer.shadowOpacity = 0.0f;
frontViewLayer.shadowOffset = CGSizeMake(0.0f, 0.0f);
frontViewLayer.shadowRadius = 0.0f;
}
else {
CGFloat nPadding = 0.0f;
if ([IILUtility targetDevice] == UIUserInterfaceIdiomPad) {
_rearViewRevealWidthIpad = 60.0f;
nPadding = _rearViewRevealWidthIpad;
}
else {
_rearViewRevealWidthIphone = 35.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;
[self rearViewDeploymentForLeftPosition];
_frontViewShadowColor = [UIColor colorWithWhite:0.8f
alpha:0.0f];
[_contentView reloadShadow];
//There is a catch here. The shadow for _frontView is different from that of self.frontViewController.view
//If we do not modify the shadow for self.frontViewController.view then it overlaps with
// the shadow of _frontView. This is generally not a problem in the case when the rear view is in focus and the
//front view is toggled to the right. But if we need the front view to be shifted slighlty to the right even when
//its position is FrontViewPositionLeft, it is important to manage the shadow of self.frontViewController.view
//otherwise the shadow takes up width equal to the padding we have provided.
CALayer *frontViewLayer = self.frontViewController.view.layer;
frontViewLayer.shadowColor = [UIColor blackColor].CGColor;
frontViewLayer.shadowOpacity = _frontViewShadowOpacity;
frontViewLayer.shadowOffset = _frontViewShadowOffset;
frontViewLayer.shadowRadius = _frontViewShadowRadius;
//reset rearViewRevealWidth
[self resetRearViewRevealWidth];
}
}
这也考虑了上面提到的与阴影相关的问题。 需要从适当的位置调用此方法,例如;当视图最初加载时,执行平移或点击手势等时。