Ios 我想用swift在xcode中创建这个滑动UIVies,我用的是什么?集合视图还是表格视图?
我想用xcode和swift在我的ios应用程序中创建一个精确的屏幕。我无法创建它,我应该使用什么?collectionView还是ScroolView 导入UIKitIos 我想用swift在xcode中创建这个滑动UIVies,我用的是什么?集合视图还是表格视图?,ios,swift,xcode,tableview,collectionview,Ios,Swift,Xcode,Tableview,Collectionview,我想用xcode和swift在我的ios应用程序中创建一个精确的屏幕。我无法创建它,我应该使用什么?collectionView还是ScroolView 导入UIKit 这是我的课。它完全有效。我还添加了一个故事板的图像。链接到我的github项目: 您可以在水平视图中使用UIScrollView。并尝试对子视图的坐标进行舍入,拖动后使用p=CGPointx:yourX,y:0;scrollView.setContentOffsetp,动画:true。其中yourX=scrollItems[i]
这是我的课。它完全有效。我还添加了一个故事板的图像。链接到我的github项目:
您可以在水平视图中使用UIScrollView。并尝试对子视图的坐标进行舍入,拖动后使用p=CGPointx:yourX,y:0;scrollView.setContentOffsetp,动画:true。其中yourX=scrollItems[i]。宽度*i;你能详细描述一下这件事吗?我已经回答了下面的问题。我想你可以在ViewController上添加点,然后在methodAnimation中更改它。你解决了你的问题吗?你能把你的源代码分享给我吗anujbidkar8@gmail.com或者分享github链接谢谢
class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
@IBOutlet weak var newCollectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
newCollectionView.delegate = self
newCollectionView.dataSource = self
// Do any additional setup after loading the view, typically from a nib.
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: view.frame.height)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
}
class ViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var scroll: UIScrollView!
@IBOutlet var btns: [UIView]!
override func viewDidLoad() {
super.viewDidLoad()
scroll.delegate = self
}
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
methodAnimation()
}
func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
methodAnimation()
}
func methodAnimation() {
if btns.count == 0 {return}
var i = 0
// i – calculate it, it is your visible/desirable view.
// here is variant of code
let dragOffset = view.frame.width * 0.5 // callibrate it for you
let offX = scroll.contentOffset.x
i = Int(offX + dragOffset) / Int(view.frame.width)
i = max(0, min(i, btns.count - 1))
let yourX = btns[i].frame.width * CGFloat(i) // ()
let p = CGPoint(x: yourX, y: 0);
scroll.setContentOffset(p, animated: true)
}
}