我试图在UICollectionView中实现一个搜索栏作为UICollectionViewReusableView
这样我就不使用UISearchController但是我正在更改collectionview的数据源
在我的自定义布局中,我以这种方式添加搜索栏:
override func prepareLayout() {
super.prepareLayout()
var searchBarAttributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: TeacherSearchbarIdentifier, withIndexPath: NSIndexPath(forItem: 0, inSection: 0))
searchBarAttributes.frame = CGRectMake(0, 0, collectionViewContentSize().width, 44)
searchBarAttributes.zIndex = 100
miscAttributes.append(searchBarAttributes)
}
override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? {
var attributes = [UICollectionViewLayoutAttributes]()
for (idx, attr) in enumerate(miscAttributes) {
if CGRectIntersection(rect, attr.frame) != CGRectNull {
attributes.append(attr)
}
}
return attributes
}
Run Code Online (Sandbox Code Playgroud)
我正在设置这样的委托:
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
var view = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: kind, forIndexPath: indexPath) as! …Run Code Online (Sandbox Code Playgroud) 我在3D编程方面遇到了更多的数学问题,我希望你能帮助我!
我正在尝试使用具有等角度的Scenekit创建3D游戏.
这段代码创建了我的正交相机:
var cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.name = "Camera"
cameraNode.position = SCNVector3Make(-5.0, -5.0, 10.0)
cameraNode.eulerAngles = SCNVector3Make(PI / 3.0, 0.0, -PI / 4.0)
cameraNode.camera?.usesOrthographicProjection = true
cameraNode.camera?.orthographicScale = 7.0
scene.rootNode.addChildNode(cameraNode)
Run Code Online (Sandbox Code Playgroud)
现在我想使用平移手势移动相机,产生滚动感.为了实现这一点,相机不应垂直移动,只能水平移动.移动时,屏幕上的触摸位置和3D世界中未投影的位置应保持不变.
我考虑过计算2D平移到3D差异并忽略垂直分量.这段代码实际上可以工作,几乎可以产生所需的结果,但速度不正确.如果我平移,相机似乎加速并且没有正确反应:
var previousTranslation = CGPointMake(0.0, 0.0)
func pan(gesture: UIPanGestureRecognizer)
{
let view = self.view as SCNView
let translation = gesture.translationInView(view)
let location = gesture.locationInView(view)
let diffTrans = translation - previousTranslation
previousTranslation = translation
let cameraNode = scene.rootNode.childNodeWithName("Camera", recursively: false)
let worldPointTrans = view.unprojectPoint(SCNVector3Make(-Float(diffTrans.x), -Float(diffTrans.y), 0.0)) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 UICollectionViewController 创建一个类似的 iCalendar。现在我正在尝试添加可重用视图作为每天的列标题。
我制作了一个故事板并添加了一个链接到此类的 UICollectionViewController:
import UIKit
class WeekViewController: UICollectionViewController, UICollectionViewDelegate
{
let dataSource = WeekViewDataSource()
let weekLayout = WeekViewLayout()
override func awakeFromNib() {
var columnHeaderViewNIB = UINib(nibName: "ColumnHeaderView", bundle: nil)
self.collectionView?.registerNib(columnHeaderViewNIB, forSupplementaryViewOfKind: columnHeaderViewIdentifier, withReuseIdentifier: columnHeaderViewIdentifier)
self.collectionView?.collectionViewLayout = weekLayout
self.collectionView?.dataSource = dataSource
super.awakeFromNib()
}
}
Run Code Online (Sandbox Code Playgroud)
ColumnHeaderView nib 实际上是一个 xib 文件,其视图包含单个标签。该视图链接到此类:
import UIKit
class ColumnHeaderView: UICollectionReusableView
{
@IBOutlet weak var label: UILabel!
}
Run Code Online (Sandbox Code Playgroud)
数据源和布局:
import UIKit
class WeekViewDataSource: NSObject, UICollectionViewDataSource {
var events = Array<String>()
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: …Run Code Online (Sandbox Code Playgroud)