小编Edo*_*Cal的帖子

两个节点之间没有检测到ARKit的冲突

我创建了两个节点:一个球体和一个盒子:

    var sphere = SCNNode(geometry: SCNSphere(radius: 0.005))
    //I get the box node from scn file
    let boxScene = SCNScene(named: "art.scnassets/world.scn")!
    var boxNode: SCNNode?
Run Code Online (Sandbox Code Playgroud)

我想要两个节点或physicsBody进行交互,所以我为categoryBitMask和创建了一个类别contactTestBitMask:

struct CollisionCategory: OptionSet {
    let rawValue: Int
    static let box = CollisionCategory(rawValue: 1)
    static let sphere = CollisionCategory(rawValue: 2)
} 
Run Code Online (Sandbox Code Playgroud)

在这里,我将盒子节点设置为物理体:

self.boxScene.rootNode.enumerateChildNodes { (node, _) in
    if node.name == "box" {
        boxNode = node
        let boxBodyShape = SCNPhysicsShape(geometry: SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0.1), options: nil)
        let physicsBody = SCNPhysicsBody(type: …
Run Code Online (Sandbox Code Playgroud)

collision nodes skphysicsbody swift arkit

5
推荐指数
1
解决办法
188
查看次数

RxJava使用优化请求

今天我试着解决一个小小的挑战:

您是一家拥有500个办事处的大公司,您想要计算全球收入(每个办事处的收入总和).

每个办公室都提供服务以获得收入.该呼叫需要一定的延迟(网络,数据库访问,......).

显然,您希望尽可能快地获得全球收入.

首先我在python中尝试了非常好的结果:

import asyncio
import time

DELAYS = (475, 500, 375, 100, 250, 125, 150, 225, 200, 425, 275, 350, 450, 325, 400, 300, 175)


class Office:

    def __init__(self, delay, name, revenue):
        self.delay = delay
        self.name = name
        self.revenue = revenue

    async def compute(self):
        await asyncio.sleep(self.delay / 1000)
        print(f'{self.name} finished in {self.delay}ms')
        return self.revenue


async def main(offices, totest):
    computed = sum(await asyncio.gather(*[o.compute() for o in offices]))
    verdict = ['nok', 'ok'][computed == totest]
    print(f'Sum of revenues = {computed} …
Run Code Online (Sandbox Code Playgroud)

java rx-java rx-java2

5
推荐指数
1
解决办法
97
查看次数

如何自定义 MKAnnotation pin 的图像

我正在尝试更改内部的图像MKAnnotation而不删除圆形形状。

在这里我创建了一个自定义类MKAnnotation

class MapPin: NSObject, MKAnnotation {
    let title: String?
    let locationName: String
    let coordinate: CLLocationCoordinate2D
    init(title: String, locationName: String, coordinate: CLLocationCoordinate2D) {
        self.title = title
        self.locationName = locationName
        self.coordinate = coordinate
    }
}
Run Code Online (Sandbox Code Playgroud)

这里我创建了一个MapPin并将其添加到mapView中

func setPinUsingMKAnnotation() {
   let pin1 = MapPin(title: "Here", locationName: "Device Location", coordinate: CLLocationCoordinate2D(latitude: 21.283921, longitude: -157.831661))
   let coordinateRegion = MKCoordinateRegion(center: pin1.coordinate, latitudinalMeters: 800, longitudinalMeters: 800)
   mapView.setRegion(coordinateRegion, animated: true)
   mapView.addAnnotations([pin1])
}
Run Code Online (Sandbox Code Playgroud)

第一张图片是我创建的,第二张图片是我想要的。

在此输入图像描述

我什至实现了MKMapViewDelegate

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) …
Run Code Online (Sandbox Code Playgroud)

uikit mkmapview mkannotation mkannotationview swift

3
推荐指数
1
解决办法
3276
查看次数

启动/停止图像视图旋转动画

我有一个开始/停止按钮和一个我要旋转的图像视图.

当我按下按钮时,我希望开始旋转,当我再次按下按钮时,图像应该停止旋转.我目前正在使用UIView动画,但我还没有找到一种方法来停止视图动画.

我希望图像旋转,但是当动画停止时,图像不应该返回到起始位置,而是继续动画.

var isTapped = true

    @IBAction func startStopButtonTapped(_ sender: Any) {
       ruotate()
       isTapped = !isTapped
    }

    func ruotate() {
        if isTapped {
            UIView.animate(withDuration: 5, delay: 0, options: .repeat, animations: { () -> Void in
            self.imageWood.transform =     self.imageWood.transform.rotated(by: CGFloat(M_PI_2))
            }, completion: { finished in
            ruotate()
            })
    }  }
Run Code Online (Sandbox Code Playgroud)

这是我的代码,但它不像我的方面那样工作.

animation ios swift

0
推荐指数
2
解决办法
3642
查看次数