Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift UIView按钮,用于在容器视图中的六个UIViewController之间导航_Swift_Xcode_Uiviewcontroller_Uibutton_Container View - Fatal编程技术网

Swift UIView按钮,用于在容器视图中的六个UIViewController之间导航

Swift UIView按钮,用于在容器视图中的六个UIViewController之间导航,swift,xcode,uiviewcontroller,uibutton,container-view,Swift,Xcode,Uiviewcontroller,Uibutton,Container View,我对Swift、面向对象编程和界面构建非常陌生(我只有一些MATLAB编程的经验),我花了大约一个星期的时间才在IB中设计出一个工作界面。我已经尝试了很多视图控制器的排列方式——容器视图,有没有连接到segue的UIButton,有没有导航控制器,现在我不知道该尝试什么(我看到的堆栈溢出页面最终创建了更多我想做的bug) 最终,我希望用户能够使用UIButton在视图控制器中容器视图内的六个UIViewController之间导航(有点像视图之间手动操作的幻灯片放映)。我尝试过UIAbbarCo

我对Swift、面向对象编程和界面构建非常陌生(我只有一些MATLAB编程的经验),我花了大约一个星期的时间才在IB中设计出一个工作界面。我已经尝试了很多视图控制器的排列方式——容器视图,有没有连接到segue的UIButton,有没有导航控制器,现在我不知道该尝试什么(我看到的堆栈溢出页面最终创建了更多我想做的bug)

最终,我希望用户能够使用UIButton在视图控制器中容器视图内的六个UIViewController之间导航(有点像视图之间手动操作的幻灯片放映)。我尝试过UIAbbarController和UINavigationController,但我不想要选项卡或导航栏


我为没有提供任何代码提前表示歉意,但我确实在一个月前学会了Swift,并且在学习的过程中也在学习。尽管如此,我已经在IB中上传了我的一次尝试(显示了六个UIViewController中的两个,因为由于bug,我还没有将它们全部放进去)。在所附图像中,第二个视图位于第一个视图的顶部,而不仅仅是容器视图。感谢您提供的任何帮助。

我将如何做非常简单。创建一个集合视图,其中包含所需视图数量的单元格。假设5个。 每个单元格都有自己的UIView,带有嵌入式ViewController。每个视图都要执行5次。这应该是最困难的部分

下一步是创建按钮,我猜您有两个按钮,一个后退<,一个前进>。然后按下按钮,在集合视图中,您只需使用以下命令增加到下一页:

   [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
这应该能奏效

有关如何更改单元格大小的示例

func collectionView(_ collectionView: UICollectionView,
            layout collectionViewLayout: UICollectionViewLayout,
            sizeForItemAt indexPath: IndexPath) -> CGSize {
    // your code here
}
对于每个单元格的不同视图,创建一个cellId1、cellId2、cellId3等,并为每个单元格id注册一个新单元格

collectionView.register(UICollectionViewCell.self,forCellWithReuseIdentifier:“Cell”)

这就是如何为视图设置不同的单元格

func collectionView(collectionView:UICollectionView,cellForItemAt indexPath:indexPath)->UICollectionViewCell{
let cell=collectionView.dequeueReusableCell(withReuseIdentifier:“cell”,for:indexath)
返回单元
}


这应该足以让您继续使用。

非常感谢!如何让每个单元格占据集合视图的整个大小?如果是这样,如何编辑视图以获得适当的设计?