Visualização Swift Collection Rolagem horizontal e vertical
Eu quero fazer essa visualização de coleção que pode rolar horizontal e vertical ... mas eu quero fazer algo assim
https://giphy.com/gifs/lWshqs2BuvilYuE4Fl/html5
pelo que vejo, há como exibição de coleção e alguns controles segmentados no topo dessa exibição de coleção ... quero dizer, meu único problema é como posso rolar horizontalmente de qualquer lugar na tela?
como se eu não tivesse que rolar a partir desse controle segmentado superior, também posso deslizar a partir dessa coisa de visualização de coleção
Alguma ideia de como fazer isso? porque eu realmente não sei se estou certo ou não .....
obrigado
* editar, não posso usar a biblioteca, então acho que preciso de algo que realmente faça isso manualmente, e para a rolagem horizontal preciso de dados dinâmicos, não sei o controlador de paginação pode usar uma causa de dados dinâmicos, contanto que eu conheça seus dados estáticos .
Respostas
pegue um viewcontroller
adicione uma vista 2 dê a ela uma restrição superior e altura de 44
adicione scrollview e dê uma restrição de criação (programaticamente ou usando storyborad a escolha é sua)
adicione 3 botões para voucher, assinatura, missão.
crie 3 ViewControllers diferentes para voucher, assinatura e missão.
adicionar 3 controladores de visualização em scrollview
// define this variable globally
var previousPageXOffset: CGFloat = 0.0
var pagenumber = 0
// add this in viewdidload
let aViewController = self.storyboard!.instantiateViewController(withIdentifier: "voucher") as! voucher
let bViewController = self.storyboard!.instantiateViewController(withIdentifier: "subscription") as! subscription
let cViewController = self.storyboard!.instantiateViewController(withIdentifier: "misson") as! misson
let bounds = UIScreen.main.bounds
let width = bounds.size.width
let height = CGFloat(1.0)
let viewControllers = [aViewController, bViewController, cViewController]
self.scrollview!.contentSize = CGSize(width: CGFloat(self.totalscreen)*width, height: height)
var idx:Int = 0
for viewController in viewControllers {
self.addChild(viewController)
let originX:CGFloat = CGFloat(idx) * width
viewController.view.frame = CGRect(x: originX, y: 0, width: self.scrollview.frame.width, height: self.scrollview.frame.height)
self.scrollview!.addSubview(viewController.view)
print("change")
viewController.didMove(toParent: self)
idx+=1
}
// delegate for scrollview
extension yourVC: UIScrollViewDelegate{
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
previousPageXOffset = scrollView.contentOffset.x
}
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let targetOffset = targetContentOffset.pointee
if targetOffset.x == previousPageXOffset {
// page will not change
} else if targetOffset.x < previousPageXOffset {
print("left")
pagenumber = pagenumber - 1
} else if targetOffset.x > previousPageXOffset {
print("ryt")
pagenumber = pagenumber + 1
}
if pagenumber <= 0 {
//set buttons colors or bottom line in your case if first page is selected
}else if pagenumber == 1{
//set buttons colors or bottom line in your case if second page is selected
}else{
//set buttons colors or bottom line in your case if third page is selected
}
print(pagenumber)
previousPageXOffset = targetOffset.x
print(previousPageXOffset)
}
}
- função para botão espacial (3 botões principais) clique
func scrollToPage(page: Int, animated: Bool) {
var frame: CGRect = self.scrollview.frame
frame.origin.x = frame.size.width * CGFloat(page)
frame.origin.y = 0
self.scrollview.scrollRectToVisible(frame, animated: animated)
}
Espero que funcione para você :)
adicione visualização de coleção a cada controlador de visualização (tela) e aplique a Parchmentestrutura para a saída necessária.
você pode obter mais informações sobre o pergaminho em: - https://github.com/rechsteiner/Parchment
anexar algumas estruturas semelhantes (selecione de acordo com sua necessidade)
- https://github.com/kitasuke/PagingMenuController
- https://github.com/tamanyan/SwiftPageMenu
- https://github.com/EndouMari/TabPageViewController
- https://github.com/PageMenu/PageMenu