Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios int似乎是在重置简单游戏中的下降按钮_Ios_Uibutton_Int_Nstimer - Fatal编程技术网

Ios int似乎是在重置简单游戏中的下降按钮

Ios int似乎是在重置简单游戏中的下降按钮,ios,uibutton,int,nstimer,Ios,Uibutton,Int,Nstimer,我还是个新手,我会尽量让它简单 这个游戏有两个星象(按钮),使用nstimer和cgpointmake从屏幕顶部下降到底部。如果你点击一个星象,屏幕上会有一个标签,在你的分数上加一分,星象会回到顶部再次下降 我遇到的问题是,如果我点击一个星体,它们都会转到顶部并同时重置 我把范围缩小到我认为问题在于它与每次点击星象时更新分数标签的int有关 任何帮助都会很有帮助,我在互联网上到处找都找不到帮助。多谢各位 整数是点 第一个astroid按钮是astroid1 第二个astroid按钮是astro

我还是个新手,我会尽量让它简单

这个游戏有两个星象(按钮),使用nstimer和cgpointmake从屏幕顶部下降到底部。如果你点击一个星象,屏幕上会有一个标签,在你的分数上加一分,星象会回到顶部再次下降

我遇到的问题是,如果我点击一个星体,它们都会转到顶部并同时重置

我把范围缩小到我认为问题在于它与每次点击星象时更新分数标签的int有关

任何帮助都会很有帮助,我在互联网上到处找都找不到帮助。多谢各位

  • 整数是点

  • 第一个astroid按钮是astroid1

  • 第二个astroid按钮是astroid2

  • 这是一个天文式的秋天

这是视图控制器

#import <UIKit/UIKit.h>

int point;

@interface ViewController : UIViewController  {

IBOutlet UIButton *astroid1;
IBOutlet UIButton *astroid2;
IBOutlet UILabel *pointlabel;

NSTimer *astroidsfall;

}

-(IBAction)astroidone:(id)sender;
-(IBAction)astroidtwo:(id)sender;
-(IBAction)start:(id)sender;


@end

如果没有关闭“自动布局”,那么这就是问题所在。使用“自动布局”时不应设置任何帧。您应该在按钮和屏幕顶部之间设置一个约束,并在代码中修改其常量值以移动按钮。

如果您没有关闭自动布局,那么这就是问题所在。使用自动布局时不应设置任何帧。那么如何为每个设备设置帧?有没有一种方法可以为每一个都有一个故事板?@neverpoops,如果你使用自动布局和大小类,你不需要为每一个都有一个故事板。你说过自动布局是我的问题吗?我是新来的,我在哪里设置了框架?@neverpoops,设置中心就是设置框架。只有当您不正确地使用自动布局时,它才是一个问题。如果你知道如何使用它,你就可以更容易地构建一个适用于所有屏幕大小的应用程序。非常感谢你,伙计,你不知道我为此奋斗了多久:D像你这样的人激发了新朋友的动力
@implementation ViewController

-(IBAction)start:(id)sender {
    astroidsfall = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self   selector:@selector(astroidphysics) userInfo:nil repeats:YES];
}

-(void)astroidphysics {
    astroid1.center = CGPointMake(astroid1.center.x, astroid1.center.y + 1);
    astroid2.center = CGPointMake(astroid2.center.x, astroid2.center.y + 1);
}

-(IBAction)astroidone:(id)sender {
    astroid1.center = CGPointMake(astroid1.center.x, astroid1.center.y - 300);

    point += 1;
    pointlabel.text = [NSString stringWithFormat:@"%i", point];
}