ios 同一时间只能有一个滑动方向
发布网友
发布时间:2022-04-22 04:17
我来回答
共1个回答
热心网友
时间:2022-04-22 05:47
整体可以超出部分左右滑动,但是表体同样需要可以超出部分上下滑动,但是表头不能跟着上下滑动. 在安卓上没有任何问题, 可是在IOS上客户就反应了, 在整体左右滑动的时候, 手指放在表体上只能上下滑动, 左右滑动的功能无法实现, 想要左右滑动必须在表头上左右滑动才能实现
IOS第三方侧滑 怎么*只侧滑一个方向
1 )方法①
首先注意要导入相关的头文件,并且Link the QuartzCore.framework
然后在storyboard中添加三个navigation视图,分别表示中间,左边和右边的视图,并且创建相应的controller。
我的处理是初始化一个IIViewDeckController 实例然后作为子视图添加到最左边的视图中,而用右边的三个navigation视图 作为IIViewDeckController 实例对象的初始参数。
其中要注意的是,要分别在三个navigation视图添加identifier,注意是添加到的是navigation controller对应的视图(即第一个)。
下面看看代码:
[cpp] view plaincopyprint?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
CenterViewController *centerController = (CenterViewController *)[storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"];
LeftViewController *leftController = (LeftViewController *)[storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"];
RightViewController *rightController = (RightViewController *)[storyboard instantiateViewControllerWithIdentifier:@"RightViewController"];
self.containerController = [[IIViewDeckController alloc] initWithCenterViewController:centerController leftViewController:leftController rightViewController:rightController];
self.containerController.leftSize = 100;
self.containerController.rightSize = 200;
self.containerController.view.frame = self.view.bounds;
[self.view addSubview:self.containerController.view];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
CenterViewController *centerController = (CenterViewController *)[storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"];
LeftViewController *leftController = (LeftViewController *)[storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"];
RightViewController *rightController = (RightViewController *)[storyboard instantiateViewControllerWithIdentifier:@"RightViewController"];
self.containerController = [[IIViewDeckController alloc] initWithCenterViewController:centerController leftViewController:leftController rightViewController:rightController];
self.containerController.leftSize = 100;
self.containerController.rightSize = 200;
self.containerController.view.frame = self.view.bounds;
[self.view addSubview:self.containerController.view];
}
复制代码
这里创建一个IIViewDeckController 实例,然后把这个实例对象的视图作为子视图添加到这个view中,这样就实现了跳转到我们需要的IIViewDeckController那里了,让我们 创建的IIViewDeckController实例处理左右滑动出现侧边栏的任务了。
(2 )方法②
这里再介绍一种实现方式:让最左边这个视图继承自IIViewDeckController然后在实现文件添加这个方法:
[cpp] view plaincopyprint?
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
self = [super initWithCenterViewController:[storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"]
leftViewController:[storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"]
rightViewController:[storyboard instantiateViewControllerWithIdentifier:@"RightViewController"]];
if (self) {
// Add any extra init code here
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
self = [super initWithCenterViewController:[storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"]
leftViewController:[storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"]
rightViewController:[storyboard instantiateViewControllerWithIdentifier:@"RightViewController"]];
if (self) {
// Add any extra init code here
}
return self;
}
复制代码
实现的效果是:
实现方式二(不使用第三方库):
下面简单说说这种滑动出现 侧边栏是怎么回事,明显这就是一个视图层叠,那么简单点的话,就是往一个视图里面添加几个视图,然后添加swipe手势,左右滑动时,响应事件处理,在事 件处理中让最上面的视图的位置发生变化,也就是视图移动,这样就可以显示出下面的视图,这样大致就可以解决了。
这里同样也是使用storyboard。而且storyboard里面的内容和上面的一样(其实解决方式借鉴了上面的方法①)。
首先分别创建对应的中间,左边,右边视图的controller(tableview controller)。
然后创建三个对应的属性
[cpp] view plaincopyprint?
@property(nonatomic, strong) MainViewController *centerController;
@property(nonatomic, strong) RightViewController *rightController;
@property(nonatomic, strong) LeftViewController *leftController;
@property(nonatomic, strong) MainViewController *centerController;
@property(nonatomic, strong) RightViewController *rightController;
@property(nonatomic, strong) LeftViewController *leftController;
复制代码