小编dan*_*_au的帖子

iphone代码 - CGPoint问题

我有10个移动对象(UIImageView),
有没有更好的方法来编写这段代码?

    - (void) jumpOnTimer {

        jumpBall1.center = CGPointMake(jumpBall1.center.x+pos1.x,jumpBall1.center.y+pos1.y);

        if(jumpBall1.center.x > 60 || jumpBall1.center.x < 0)
            pos1.x = -pos1.x;
        if(jumpBall1.center.y > 211 || jumpBall1.center.y < 82)
            pos1.y = -pos1.y;

        jumpBall2.center = CGPointMake(jumpBall2.center.x+pos2.x,jumpBall2.center.y+pos2.y);

        if(jumpBall2.center.x > 40 || jumpBall2.center.x < 0)
            pos2.x = -pos2.x;
        if(jumpBall2.center.y > 206 || jumpBall2.center.y < 82)
            pos2.y = -pos2.y;

and so on...
Run Code Online (Sandbox Code Playgroud)

iphone objective-c

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

iPhone代码 - CGPoint分配问题

我试图实现这个移动UIImageView对象的代码,
我在createPosition方法中得到了对象(jumpBall1 ...)的编译器警告:UIImageView may not respont to -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 …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c

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

标签 统计

iphone ×2

objective-c ×2