小编sat*_*ikb的帖子

SKFieldNode magneticNode吸引力

我目前正在使用iOS 8 SpriteKit API,并且很难用SKFieldNode创建一个有吸引力的磁力.我可以很好地制造一个相反的磁力,但我无法扭转这个领域.这是我目前所拥有的:

    touchField = [SKFieldNode magneticField];

    touchField.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:(self.frame.size.height/4 - 34)];

    touchField.physicsBody.charge = 3;
Run Code Online (Sandbox Code Playgroud)

该特定字段应该与另一个SKSpriteNode交互.

sprite-kit skphysicsbody ios8

7
推荐指数
1
解决办法
2035
查看次数

Matplotlib 只保存没有空格的文本

所以在python中我有以下代码,取自这个答案:

import matplotlib.pyplot as plt                                                 
import sympy                                                                    

x = sympy.symbols('x')                               
y = 1 + sympy.sin(sympy.sqrt(x**2 + 20))                                         
lat = sympy.latex(y)                                                            

#add text                                 
plt.text(0, 0.6, r"$%s$" % lat, fontsize = 50)                                  

#hide axes                                                                      
fig = plt.gca()                                                                 
fig.axes.get_xaxis().set_visible(False)                                         
fig.axes.get_yaxis().set_visible(False)                                         
plt.savefig('out.png', bbox_inches='tight', pad_inches=0)                                                        
plt.show()
Run Code Online (Sandbox Code Playgroud)

这将打开文本并将其导出到 png 文件就好了:

图像导出 1

但这包括框架外空白之外的空白。您将如何裁剪图像以仅导出文本,例如边界框,像这样?

在此处输入图片说明

python matplotlib sympy

6
推荐指数
1
解决办法
944
查看次数

Swift CGAffineTransformScale到一个比例,而不是一个比例

假设我使用CGAffineTransformScale缩放UILabel,如下所示:

let scale = 0.5
text = UILabel(frame: CGRectMake(100, 100, 100, 100))
text.text = "Test"

UIView.animateWithDuration(2.0, delay: 0.0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
    self.text.transform = CGAffineTransformScale(self.text.transform, scale, scale)
}, completion: {(value : Bool) in
    print("Animation finished")
})
Run Code Online (Sandbox Code Playgroud)

当我想将UILabel缩小一半时,这很有用.但是,如果我再次调用相同的代码,它将以0.25的比例结束,因为它再次缩放一半.

是否可以使用CGAffineTransformScale始终缩放到原始UILabel帧的一半大小,而不是累积缩放?

uilabel ios cgaffinetransformscale swift

5
推荐指数
2
解决办法
7992
查看次数

CAShapeLayer在动画Swift期间检测触摸

我可以检测到这样的触摸CAShapeLayer(touchesEnded):

let touchLocation : CGPoint = (touch as! UITouch).locationInView(self.view)

for shape in shapes{
    if CGPathContainsPoint(shape.path, nil, touchLocation, false){
        print("Layer touch")
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以像这样动画CAShapeLayer的路径:

let newShapePath = UIBezierPath(arcCenter: toPoint, radius: 20, startAngle: CGFloat(0), endAngle: CGFloat(M_PI * 2), clockwise: true).CGPath

// animate the `path`
let animation = CABasicAnimation(keyPath: "path")
animation.toValue = newShapePath
animation.duration = CFTimeInterval(duration)

animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
animation.fillMode = kCAFillModeBoth
animation.removedOnCompletion = false

shape.addAnimation(animation, forKey: animation.keyPath)
Run Code Online (Sandbox Code Playgroud)

但是当动画发生时,CAShapeLayer上没有检测到触摸.是否可以在动画路径时检测CAShapeLayer上的触摸?

core-animation cabasicanimation cashapelayer ios swift

2
推荐指数
1
解决办法
926
查看次数