我正在尝试使用collectionView实现类似旋转木马的效果.我实现UICollectionView并设置它以水平显示单元格.
唯一的问题是如何只允许一个单元格的出现并将该单元格置于屏幕中心.
注意:启用了分页.
我找到了这个代码,尝试过但遗憾的是没有用
代码参考:使用Swift创建一个Paging UICollectionView
override func targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
if let cv = self.collectionView {
let cvBounds = cv.bounds
let halfWidth = cvBounds.size.width * 0.5;
let proposedContentOffsetCenterX = proposedContentOffset.x + halfWidth;
if let attributesForVisibleCells = self.layoutAttributesForElementsInRect(cvBounds) {
var candidateAttributes : UICollectionViewLayoutAttributes?
for attributes in attributesForVisibleCells {
// == Skip comparison with non-cell items (headers and footers) == //
if attributes.representedElementCategory != UICollectionElementCategory.Cell {
continue
}
if let candAttrs …Run Code Online (Sandbox Code Playgroud) 将底线边框添加到的最佳方法是TextView什么?我已经尝试过了,但似乎行不通。它受滚动能力的影响,textview并且在TextView
func addBottomBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.CGColor
border.frame = CGRectMake(0, self.frame.size.height - width, self.frame.size.width, width)
self.layer.addSublayer(border)
self.layer.masksToBounds = true
}
Run Code Online (Sandbox Code Playgroud)
编辑:TextView具有动态高度。
我在 ScrollView 内的视图中的视图中有一个按钮:
UIScrollView
-ContentView
--PhoneNumberView
---UIButton
Run Code Online (Sandbox Code Playgroud)
如果 ScrollView 的滚动能力被禁用,按钮会正常点击。但是,如果启用滚动,则按钮似乎被禁用。
这是我发送 ScrollView 的内容大小的方式:
var contentRect = CGRectZero;
for view in self.contentView.subviews {
contentRect = CGRectUnion(contentRect, view.frame)
}
scrollView.contentSize = contentRect.size
scrollView.contentSize.height = scrollView.contentSize.height+20
Run Code Online (Sandbox Code Playgroud)
我还设置了这些属性
scrollView.userInteractionEnabled = true
scrollView.exclusiveTouch = true
scrollView.canCancelContentTouches = true
scrollView.delaysContentTouches = true
Run Code Online (Sandbox Code Playgroud)
我终于尝试创建 UIScrollView 的子类,我最终得到了这个:
class myScrollView: UIScrollView {
override func touchesShouldCancelInContentView(view: UIView) -> Bool {
return false
}
}
Run Code Online (Sandbox Code Playgroud)
但只要有任何滚动,按钮仍然不活动。
我该如何解决?
因为我做了一些我希望保留的提交,所以从 GitHub 删除提交而不影响我的本地存储库的最佳方法是什么?
Github 存储库有两个错误的提交,我希望将其删除,同时将提交保留在本地存储库中。