我正在快速制作SpriteKit的第一个场景.我为尺寸为640x1136的4英寸iPhone创建了一个背景图像.我将图像作为精灵放置在屏幕的中央,但图像不是全屏,缺少边缘.
接下来,我尝试在app中调整图像大小.当我这样做image.size.height = self.size.height的高度在整个iPhone屏幕上正确调整大小.但是当我用宽度做同样的事情时image.size.width = self.size.width,画面的宽度非常明显.
我打印尺寸,self.size结果我的iPhone 5s的尺寸是1024,768.这完全是胡说八道,因为屏幕不能比iPhone上的高度宽.该应用程序是通用的,但唯一的方向设置为纵向.
编辑:这是我用来将图像放在屏幕上的代码
class GameScene: SKScene
{
let menuImage = SKSpriteNode(imageNamed: "menuImage")
override func didMoveToView(view: SKView)
{
/* Setup your scene here */
menuImage.anchorPoint = CGPointMake(0.5, 0.5)
menuImage.size.height = self.size.height
menuImage.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
self.addChild(menuImage)
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试与Google Firebase进行聊天。我正在按照教程进行操作,但是由于使用了未声明的变量并且无法在任何地方找到其来源,因此无法继续。该变量称为kGCMMessageIDKey。
它首先在这里用作:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (userInfo[kGCMMessageIDKey]) {
NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
}
Run Code Online (Sandbox Code Playgroud)
在示例项目中,kGCMMessageIDKey在AppDelegate中声明为
NSString *const kGCMMessageIDKey = @"gcm.message_id";。
我感觉这是我应该从Firebase仪表板获取的常数,但是我也找不到任何相应的ID。
Stripe在文档中提供了使用示例,他们在应用程序的根部PaymentElement创建组件并将其包装在整个网站上。<Elements>这与能够使用useStripe和useElements挂钩从应用程序内的任何位置访问条带对象非常有效。
然而,当他们在根创建元素时,他们还指定options包含clientPromise. clientPromise只有在知道所购买的物品后才能获得。因此,我需要clientPromise在处理结账的子组件中生成 。
Stripe 文档代码
const stripePromise = loadStripe('fake_test_key');
function App() {
const options = {
// passing the client secret obtained from the server
clientSecret: fetchClientSecretFromServer(),
};
return (
<Elements stripe={stripePromise} options={options}>
<CheckoutForm />
</Elements>
);
};
Run Code Online (Sandbox Code Playgroud)
有没有办法手动设置 clientPromise,或者覆盖子组件中的条带选项,<Elements>而不必在渲染 ` 组件时生成它?
我正在使用以下方式存储对图像项目的引用:const renderedImageRef = useRef()。然后使用以下方法在函数中分配 ref render():
<img ref={renderedImageRef} src=... />
Run Code Online (Sandbox Code Playgroud)
在下面的另一个 JSX 项目中,我尝试renderedImageRef.current.clientHeight使用以下方式进行访问:
<div style={{top:`${renderedImageRef.current.clientHeight}px`}}>
Hello world
</div>
Run Code Online (Sandbox Code Playgroud)
但这会在控制台中产生错误:
Uncaught TypeError: Cannot read properties of undefined (reading 'clientHeight')
Run Code Online (Sandbox Code Playgroud)
renderedImageRef.current.clientHeight奇怪的是,如果我尝试从钩子内部访问useEffect,它会正确显示高度:
useEffect(() => {
if(renderedImageRef !== null) {
console.log(renderedImageRef)
}
}, [renderedImageRef])
Run Code Online (Sandbox Code Playgroud)
为什么我收到控制台错误?
我正在尝试编辑在.h文件中声明并在.m文件中合成的NSMutable数组中的对象,但应用程序崩溃与调试说: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object'
导致应用程序崩溃的行是:
[noteContent replaceObjectAtIndex:currentNote withObject:noteText.text];
Run Code Online (Sandbox Code Playgroud)
noteContent在.h中声明@property (nonatomic, strong) NSMutableArray* noteContent;,在.m中合成@synthesize noteContent并在viewDidLoad中初始化
noteContent = [[NSMutableArray alloc] init];
noteContent = [standardUserDefaults objectForKey:@"noteContent"];
Run Code Online (Sandbox Code Playgroud)
问题不在于替换nil对象,因为我检查了该位置,存储了一个实际的字符串.
感谢你的付出.
ViewController我想创建在 .h 文件开头导入的类型变量
KTOneFingerRotationGestureRecognizer.h
#import <UIKit/UIKit.h>
@class ViewController.h;
@interface KTOneFingerRotationGestureRecognizer : UIGestureRecognizer
{
ViewController* mainViewController; // error: Unknown type name `ViewController`; did you mean `UIViewController`?
}
@property (nonatomic, assign) CGFloat rotation;
@property (nonatomic, strong) ViewController* mainViewController; // error: Unknown type name `ViewController`; did you mean `UIViewController`?
@end
Run Code Online (Sandbox Code Playgroud)
我需要这些变量位于头文件中,因为它们必须可以从类外部访问和分配。
谢谢
编辑:
感谢您的回复。正如 LostInTransit 所建议的,错误是由于ViewController从KTOneFingerRotationGestureRecognizer和KTOneFignerRotationGestureRecognizer从导入而发生的ViewController。按照建议,我将其更改#import "ViewController.h"为@class ViewController;消除了错误,但现在我的代码无法使用。
访问的目的ViewController是我想ViewController从中检索对象的位置KTOneFingerRotationGestureRecognizer,但@class声明不允许我访问该变量。我来演示一下。
视图控制器.h
#import <UIKit/UIKit.h> …Run Code Online (Sandbox Code Playgroud)