我有一个SCNBox对象通过SCNNode添加到SCNScene ...
let box:SCNBox = SCNBox(width: 4, height: 4, length: 4, chamferRadius: 0.1)
box.firstMaterial?.diffuse.contents = UIColor.greenColor()
let boxNode:SCNNode = SCNNode(geometry: box)
boxNode.position = SCNVector3(x: 2, y: 2, z: 2)
scene.rootNode.addChildNode(boxNode)
Run Code Online (Sandbox Code Playgroud)
我的问题是我如何设置高度的动画(假设为40),同时盒子也不会向下生长?
我想我需要更改枢轴点以进入框的底部?
如果这是一个解决方案,我不知道如何做到这一点.
我该怎么做才能正确?
我一直在使用sendAction方法 with来传达来自to 的nil target操作,而不是实现委托。Cells(UITableViewCell/UICollectionViewCell)ViewControllers
自 Swift 2.2 以来,选择器的语法已更新,我收到一些警告。新#selector语法坚持指定selectorname后跟classname. 如果我提到类名,那么将目标设置为 nil 就没有意义。
有什么解决方法吗?
class RedeemCell: UICollectionViewCell {
@IBAction func redeemAction(sender: AnyObject) {
UIApplication.sharedApplication().sendAction("updateCartWithTotalAmountPayableWithDiscount:", to: nil, from: self, forEvent: nil)
}
}
class CartVC: UIViewController {
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: UICollectionViewCell?
cell = collectionView.dequeueReusableCellWithReuseIdentifier("redeempoints", forIndexPath: indexPath)
return cell!;
}
func updateCartWithTotalAmountPayableWithDiscount(sender: AnyObject) {
print("this will be called as the action movies through responderchain …Run Code Online (Sandbox Code Playgroud) 我正在研究一些 SceneKit 概念,而我试图在脑海中巩固的一个概念是 unprojectPoint。
我知道该函数将在 2D 中取一个点并在 3D 中返回一个点(所以一个具有正确 Z 值的点)。
当我阅读文档时,我读到了这个:
/*!
@method unprojectPoint
@abstract Unprojects a screenspace 2D point with depth info using the receiver's current point of view and viewport.
@param point The screenspace position to be unprojected.
@discussion A point whose z component is 0 (resp. 1) is unprojected on the near (resp. far) clip plane.
*/
public func unprojectPoint(_ point: SCNVector3) -> SCNVector3
Run Code Online (Sandbox Code Playgroud)
我不太清楚的是在谈论 Z 时使用的值 0 和 1 ....
z 分量为 0(分别为 1)的点在近(分别为远)剪裁平面上未投影。
当我在网上阅读时,我发现了这个问题: …
我阅读了Apple关于这两个课程的文档,但我不确定何时何时不使用哪一个?由于SCNVector3的构造函数也接受相同的参数并返回相同的东西,因此混淆了一个名为SCNVector3Make的方法
我通过使用AR套件识别图像,当检测图像时我需要在所呈现的场景上显示和播放视频(如检测到的图像上方)?
lazy var fadeAndSpinAction: SCNAction = {
return .sequence([
.fadeIn(duration: fadeDuration),
.rotateBy(x: 0, y: 0, z: CGFloat.pi * 360 / 180, duration: rotateDuration),
.wait(duration: waitDuration),
.fadeOut(duration: fadeDuration)
])
}()
lazy var fadeAction: SCNAction = {
return .sequence([
.fadeOpacity(by: 0.8, duration: fadeDuration),
.wait(duration: waitDuration),
.fadeOut(duration: fadeDuration)
])
}()
lazy var fishNode: SCNNode = {
guard let scene = SCNScene(named: "Catfish1.scn"),
let node = scene.rootNode.childNode(withName: "Catfish1", recursively: false) else { return SCNNode() }
let scaleFactor = 0.005
node.scale = SCNVector3(scaleFactor, scaleFactor, scaleFactor) …Run Code Online (Sandbox Code Playgroud) iOS 12应用程序现在允许我们创建一个ARReferenceObject,并使用它可以可靠地识别实际对象的位置和方向。我们也可以保存完成的.arobject文件。
但是:
ARReferenceObject仅包含ARKit识别实际对象所需的空间特征信息,而不是该对象的可显示3D重建。
sceneView.session.createReferenceObject(transform: simd_float4x4,
center: simd_float3,
extent: simd_float3) {
(ARReferenceObject?, Error?) in
// code
}
func export(to url: URL, previewImage: UIImage?) throws { }
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以让我们.arobject使用Poisson Surface Reconstruction或从文件中重建数字3D几何(低多边形或高多边形)Photogrammetry?
我有一个使用NSFetchedResultsController的表.这会给我一个带有标题的索引
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[_fetchedResultsController sections] count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [[[_fetchedResultsController sections] objectAtIndex:section] name];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger numberOfRows = 0;
NSArray *sections = _fetchedResultsController.sections;
if(sections.count > 0)
{
id <NSFetchedResultsSectionInfo> sectionInfo = [sections objectAtIndex:section];
numberOfRows = [sectionInfo numberOfObjects];
}
return numberOfRows;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return [_fetchedResultsController sectionIndexTitles];
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
return [_fetchedResultsController sectionForSectionIndexTitle:title atIndex:index];
}
Run Code Online (Sandbox Code Playgroud)
但我想使用UILocalizedIndexCollation来获得完整的字母表.
如何将这些方法连接到NSFetchedResultsController?
我想我需要从当前的Collation中获取索引标题
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView …Run Code Online (Sandbox Code Playgroud) 我正在努力学习Swift和研究Ch中的例子.苹果公司的一本书.最后一个练习给我带来了很多麻烦,我正在尝试构造一个函数,它返回作为参数传递的两个序列的公共元素.这是我试过的代码:
func anyCommonElements <T, U where T: SequenceType, U: SequenceType, T.Generator.Element:
Equatable, T.Generator.Element == U.Generator.Element>
(lhs: T, rhs: U) -> [T.Generator.Element] {
var result : [T.Generator.Element] // how to default-initialize it?
for lhsItem in lhs {
for rhsItem in rhs {
if lhsItem == rhsItem {
result.append(lhsItem)
}
}
}
return result
}
Run Code Online (Sandbox Code Playgroud)
我唯一的问题是我不知道如何初始化result(类型[T.Generator.Element]),因此我不能使用它来将公共元素附加到其中.我试过了明显的事
var result : [T.Generator.Element] = [T.Generator.Element]()
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误Could not find member Element,如果我尝试
var result : [T.Generator.Element] = [T.Generator.Element()]()
Run Code Online (Sandbox Code Playgroud)
编译器吐出 …
我正在 Iphone 和 Ipad 上开发游戏,就像太空入侵者一样。
要摧毁的气球从屏幕顶部直线落下。
这是我添加它们的代码:
func addBalloonv(){
var balloonv:SKSpriteNode = SKSpriteNode (imageNamed: "ballonvert.png")
balloonv.physicsBody = SKPhysicsBody (circleOfRadius: balloonv.size.width/2)
balloonv.physicsBody.dynamic = true
balloonv.physicsBody.categoryBitMask = balloonCategory | greenCategory
balloonv.physicsBody.contactTestBitMask = flechetteCategory
balloonv.physicsBody.collisionBitMask = balloonCategory
balloonv.physicsBody.mass = 1
balloonv.physicsBody.restitution = 1
balloonv.physicsBody.allowsRotation = true
let minX = balloonv.size.width/2
let maxX = self.frame.size.width - balloonv.size.width/2
let rangeX = maxX - minX
let position:CGFloat = CGFloat(arc4random()) % CGFloat(rangeX) + CGFloat(minX)
balloonv.position = CGPointMake(position, self.frame.size.height+balloonv.size.height)
self.addChild(balloonv)
Run Code Online (Sandbox Code Playgroud)
我有一个气球颜色的功能。
所以目前它们直线移动,我正在寻找从顶部和两侧的随机运动(像空气中的气球一样的湍流)。
我怎样才能做到这一点?
非常感谢 !!
我咬了一口子,开始将我的应用程序转换为Swift 3.一如既往,转换器非常需要.在这种情况下,我不确定如何正确编码新版本.这是原作:
let indexes : [CInt] = [0,1,2,3]
let dat = NSData(bytes: indexes, length: sizeofValue(indexes))
let ele = SCNGeometryElement(data:dat, primitiveType: .Triangles, primitiveCount: 2, bytesPerIndex: sizeof(Int))
Run Code Online (Sandbox Code Playgroud)
在运行转换并编写新的sizeof(谢谢)之后,我最终得到了这个:
let indexes : [CInt] = [0,1,2,3]
let dat = Data(bytes: UnsafePointer<UInt8>(indexes), count: sizeof(indexes))
let ele = SCNGeometryElement(data:dat, primitiveType: .triangles, primitiveCount: 2, bytesPerIndex: MemoryLayout<Int>.size)
Run Code Online (Sandbox Code Playgroud)
但是,这给了我(Data(bytes:length:)随叫随到):
'init'不可用:使用'withMemoryRebound(to:capacity:_)'临时查看内存作为另一种布局兼容类型.
我在这里查看了几个主题,并阅读了发布说明,并且我仍然感到困惑,我应该在这里做些什么.