我在我的应用中使用SWRevealViewContrtoller
滑出侧边菜单。哪个工作正常。但我有一个问题,如何在点击按钮或用户拖动侧边菜单时更改侧边栏按钮图像。我指的是link。
提前致谢
答案 0 :(得分:1)
尝试执行以下操作 -
方法1 (根据您的参考链接):
在您的homeVC.m
集SWRevealViewControllerDelegate
中
@interface homeVC ()<SWRevealViewControllerDelegate>
并添加viewDidLoad()
self.revealViewController.delegate = self;
然后添加此方法 -
-(void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position{
//check position here
if(position == FrontViewPositionLeft) {
[self.sideBarButton setImage:[UIImage imageNamed:@"open.png"] forState:UIControlStateNormal]; //self.sideBarButton is your toggle button IBOutlet
}
else if(position == FrontViewPositionRight) {
[self.sideBarButton setImage:[UIImage imageNamed:@"close.jpg"] forState:UIControlStateNormal];
}
}
方法2:
在sideVC.m
import
-
#import "homeVC.h"
#import "SWRevealViewController.h"
现在添加viewWillAppear()
和viewWillDisappear()
-
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
homeVC *vc=(UserProfileViewController*)self.revealViewController.frontViewController;
[vc.sideBarButton setImage:[UIImage imageNamed:@"close.jpg"] forState:UIControlStateNormal];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
homeVC *vc=(UserProfileViewController*)self.revealViewController.frontViewController;
[vc.sideBarButton setImage:[UIImage imageNamed:@"open.jpg"] forState:UIControlStateNormal];
}
方法1 与方法2 的区别在于,当sideVC
完成动画时,方法1 ,即位置设置为{{1}通过单击按钮或拖动视图,可以比按钮图像更改{}或FrontViewPositionLeft
。但是当FrontViewPositionRight
开始显示按钮图像更改并且sideVC
消失时方法2 。
答案 1 :(得分:0)
试试FRDLivelyButton。在此库中,您可以更改UIBarButton图像。
希望它有所帮助。
答案 2 :(得分:0)
添加<SWRevealViewControllerDelegate>
设置self.revealViewController.delegate = self;
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position{
//change button image below.
if(position == FrontViewPositionLeft) {
//drawer close
} else {
//drawer open
}
}
这对我有用。快乐的编码
答案 3 :(得分:0)
更新Swift 3.0
添加 SWRevealViewControllerDelegate
在 viewDidLoad()中添加此
self.revealViewController().delegate = self
func revealController(_ revealController: SWRevealViewController!, willMoveTo position: FrontViewPosition) {
if position == FrontViewPosition.left {
//drawer close
}
else {
//drawer open
}
}