我正在阅读Redux库的文档,它有这个例子,
除了读取状态之外,容器组件还可以调度操作.以类似的方式,您可以定义一个调用的函数
mapDispatchToProps(),该函数接收dispatch()方法并返回您想要注入到表示组件中的回调道具.
这实际上没有任何意义.dispatch()你已经拥有了为什么需要mapDispatchToProps?
他们还提供了这个方便的代码示例:
const mapDispatchToProps = (dispatch) => {
return {
onTodoClick: (id) => {
dispatch(toggleTodo(id))
}
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以用非专业人士的术语解释这个功能是什么以及为什么它有用?
在objective-c中使用ivars和属性的这三种方式之间的语义差异是什么?
1.
@class MyOtherObject;
@interface MyObject {
}
@property (nonatomic, retain) MyOtherObject *otherObj;
Run Code Online (Sandbox Code Playgroud)
2.
#import "MyOtherObject.h"
@interface MyObject {
MyOtherObject *otherObj;
}
@property (nonatomic, retain) MyOtherObject *otherObj;
Run Code Online (Sandbox Code Playgroud)
3.
#import "MyOtherObject.h"
@interface MyObject {
MyOtherObject *otherObj;
}
Run Code Online (Sandbox Code Playgroud) 我添加了一个UIRotationGestureRecognizer并希望使用它来旋转用户选择的节点.
目前,它围绕z轴旋转,如下所示:
private var startingRotation: CGFloat = 0
@objc private func handleRotation(_ rotation: UIRotationGestureRecognizer) {
guard let node = sceneView.hitTest(rotation.location(in: sceneView), options: nil).first?.node else {
return
}
if rotation.state == .began {
startingRotation = CGFloat(node.rotation.w)
}
node.rotation = SCNVector4(0, 0, 1, -Float(startingRotation + rotation.rotation))
}
Run Code Online (Sandbox Code Playgroud)
如果自放置节点后相机未移动,则此方法可正常工作.
但是,如果用户移动到节点的一侧,它将不再在相机所面对的轴上旋转.
如何围绕相机轴旋转?
CKContainer.discoverAllIdentities我的CloudKit应用程序中的请求总是失败.它在几天的过程中不断失败.
失败的代码的简化版本(导致相同的错误)是:
private func getContacts(completion: (([CKUserIdentity]?) -> Void)?) {
container.status(forApplicationPermission: .userDiscoverability) { [weak self] status, error in
if let error = error {
print(error)
}
switch status {
case .granted:
self?.discover(completion: completion)
default:
print("status not granted")
}
}
}
private func discover(completion: (([CKUserIdentity]?) -> Void)?) {
let op = CKDiscoverAllUserIdentitiesOperation()
op.qualityOfService = .userInitiated
op.discoverAllUserIdentitiesCompletionBlock = { error in
if let error = error {
print(error)
}
}
op.userIdentityDiscoveredBlock = { identity in
print(identity)
}
op.start()
}
Run Code Online (Sandbox Code Playgroud)
它会导致错误传递给op.discoverAllUserIdentitiesCompletionBlock.日志中的错误描述是: …
我第一次在模拟器上运行Sticker Pack扩展时遇到以下崩溃:
2017-10-25 14:56:10.513268-0700 MobileSMS[94610:5136614] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘attempt to scroll to invalid index path: <NSIndexPath: 0x60c00023b820> {length = 2, path = 0 - 9223372036854775807}’
我没有在StackOverflow上看到这个问题的答案,所以我发布了这个问题并将在下面回答.如果这不正确,请告诉我!
我正在我的设备上测试一个新应用程序,今天,我开始集成 StoreKit 以进行应用程序内购买。
问题是每次我启动应用程序时,它都会询问我的沙箱帐户密码。在下文中,您将找到有关该问题的一些详细信息。
StoreKit 开始在一个不是 rootView 的视图中做它的东西,所以我排除了我以编程方式抛出错误的情况......
那么,我之后做了什么?
问题仍然存在。请记住,要求的密码是 testuser1@t.com(第一个测试帐户!)
我知道还有其他几种方法可以做到这一点; 我不想导入任何我不需要的东西.如果有人可以帮助我使用他的代码,那就太好了.
目前,仅保存没有水印图像的原始图像.
extension UIImage {
class func imageWithWatermark(image1: UIImageView, image2: UIImageView) -> UIImage {
UIGraphicsBeginImageContextWithOptions(image1.bounds.size, false, 0.0)
image2.layer.renderInContext(UIGraphicsGetCurrentContext()!)
image1.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return img
}
}
func addWatermark() {
let newImage = UIImage.imageWithWatermark(imageView, image2: watermarkImageView)
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil)
}
Run Code Online (Sandbox Code Playgroud)
编辑:我已经在保存的图像上出现水印.
我不得不切换图层的顺序:
image1.layer.renderInContext(UIGraphicsGetCurrentContext()!)
image2.layer.renderInContext(UIGraphicsGetCurrentContext()!)
Run Code Online (Sandbox Code Playgroud)
但是,它并没有出现在正确的位置.它似乎总是出现在图像的中心.