gpt4 book ai didi

iPhone代码-CGPoint分配问题

转载 作者:行者123 更新时间:2023-12-03 20:29:49 25 4
gpt4 key购买 nike

我尝试实现移动 UIImageView 对象的代码,
我在 createPosition 方法中收到有关对象 (jumpBall1...) 的编译器警告:UIImageView 可能无法响应 -setupperLimit、-setlowerLimit、-setspeed

代码:

@interface JumpBallClass : UIViewController
{
CGPoint center;
CGPoint speed;

CGPoint lowerLimit;
CGPoint upperLimit;

IBOutlet UIImageView *jumpBall1;
IBOutlet UIImageView *jumpBall2;
}

@property (assign) CGPoint lowerLimit;
@property (assign) CGPoint upperLimit;
@property (assign) CGPoint speed;
@property(nonatomic,retain) IBOutlet UIImageView *jumpBall1;
@property(nonatomic,retain) IBOutlet UIImageView *jumpBall2;


- (void)update;

@end

@implementation JumpBallClass
- (void)update
{
center.x += speed.x;
center.y += speed.y;

if (center.x > upperLimit.x || center.x < lowerLimit.x)
{ speed.x = -speed.x; }
if (center.y > upperLimit.y || center.y < lowerLimit.y)
{ speed.y = -speed.y; }
}
@end

- (void) jumpOnTimer {

NSArray * balls = [NSArray arrayWithObjects:jumpBall1, jumpBall2, nil];

[balls makeObjectsPerformSelector:@selector(update)];
}

- (void) createPosition {
[jumpBall1 setUpperLimit:CGPointMake(60, 211)];
[jumpBall1 setLowerLimit:CGPointMake(0, 82)];
[jumpBall1 setspeed:CGPointMake(2.0,7.0)];
...
}

最佳答案

您的代码正在尝试调用您已声明为 UIImageView 的成员变量 JumpBall1 上的方法 setUpperLimit: setLowerLimit: 和 setspeed: 。然而,这些不是 UIImageView 的方法 - 它们是您在自己的自定义 JumpBallClass 中声明的 @properties 的 setter 方法。但是,您尚未在实现文件中指定这些属性的综合(使用 @synthesize 关键字)。

也许您想要做的是使 JumpBallClass 成为 UIImageView 的子类,并实例化它的两个实例,一个实例对应于您想要控制的每个 JumpBall。

@interface JumpBallClass : UIImageView
{
CGPoint center;
CGPoint speed;

CGPoint lowerLimit;
CGPoint upperLimit;

IBOutlet UIImageView *jumpBallView;
}

@property (assign) CGPoint lowerLimit;
@property (assign) CGPoint upperLimit;
@property (assign) CGPoint speed;
@property(nonatomic,retain) UIImageView *jumpBallView;

- (void)update;

@end

@implementation JumpBallClass
@synthesize lowerLimit, upperLimit, speed, jumpBallView;

- (void)update
{
center.x += speed.x;
center.y += speed.y;

if (center.x > upperLimit.x || center.x < lowerLimit.x)
{ speed.x = -speed.x; }
if (center.y > upperLimit.y || center.y < lowerLimit.y)
{ speed.y = -speed.y; }
}
@end

//assuming jumpBall1&2 have beeen declared like so:
//JumpBallClass *jumpBall1=[[JumpBallClass init] alloc];
//JumpBallClass *jumpBall2=[[JumpBallClass init] alloc];

- (void) jumpOnTimer {

NSArray * balls = [NSArray arrayWithObjects:jumpBall1, jumpBall2, nil];

[balls makeObjectsPerformSelector:@selector(update)];
}

- (void) createPosition {
[jumpBall1 setUpperLimit:CGPointMake(60, 211)];
[jumpBall1 setLowerLimit:CGPointMake(0, 82)];
[jumpBall1 setspeed:CGPointMake(2.0,7.0)];
...
}

关于iPhone代码-CGPoint分配问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1999184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com