在SWRevealViewController中修改FrontView的框架

通常情况下,如果使用SWRevealViewController,则前视图完全覆盖后视图,只有在执行某些操作(刷卡,水龙头等)时才能看到后视图。 我的要求是,当视图加载和用户向后滑动时,后视应始终至less可见一点。 我试图修改前视图的框架来实现这一点,但我没有看到任何效果。

我把帧更新帧的代码放在一个方法中:

-(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方法中调用的,提供的参数为TRUE。 这个方法也需要从SWRevealViewController中的地方调用pan和tap手势。

新的边界

这是刷视图时的样子:

刷卡

这是框架resize问题的解决scheme:

 -(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]; } } 

这也考虑了上面提到的影子相关的问题。 这个方法需要从适当的地方调用,例如: 最初加载视图时,执行平移或轻击手势等。