Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Iphone 调整大小时如何移动UIImageView?_Iphone_Objective C_Cocoa Touch_Uikit_Core Graphics - Fatal编程技术网

Iphone 调整大小时如何移动UIImageView?

Iphone 调整大小时如何移动UIImageView?,iphone,objective-c,cocoa-touch,uikit,core-graphics,Iphone,Objective C,Cocoa Touch,Uikit,Core Graphics,我试图上下移动一个UIImageView,同时使它变大。现在,当我单独做这些事情时,它的工作方式和我想象的一样,但当我把它们结合起来时,它看起来真的很有问题,就像我希望它看起来一样 这是我的代码,您可以将其复制到Xcode中,看看自己会发生什么。 使用interface builder中获得的任何图像添加UIImageView,并将此代码添加到viewController。h: IBOutlet UIImageView *bg1; int steps; float a; 然后将其发送到vi

我试图上下移动一个
UIImageView
,同时使它变大。现在,当我单独做这些事情时,它的工作方式和我想象的一样,但当我把它们结合起来时,它看起来真的很有问题,就像我希望它看起来一样

这是我的代码,您可以将其复制到Xcode中,看看自己会发生什么。 使用interface builder中获得的任何图像添加
UIImageView
,并将此代码添加到viewController。h:

IBOutlet UIImageView *bg1;

int steps;

float a;
然后将其发送到viewController.m

#define kA 3

- (void)viewDidLoad {
    [super viewDidLoad];

    steps = 0;

    a = kA;

    [NSTimer scheduledTimerWithTimeInterval:.04 target:self selector:@selector(walk)
                                            userInfo:nil repeats:YES];
}

-(void)resetA { // This function makes it possible for the UIImageView to move up and down
    if (a > 0) a=-kA;
    else a=kA;

    steps++;
    NSLog(@"%i", steps);
}

-(void)walk { // This function makes the UIImageView bigger and move up and down
    if (a > 0) [bg1 setFrame:CGRectMake(0, 0, bg1.bounds.size.width+a,  
                                              bg1.bounds.size.height+a)];
    else [bg1 setFrame:CGRectMake(0, 0, bg1.bounds.size.width-a, 
                                        bg1.bounds.size.height-a)];

    [bg1 setCenter:CGPointMake(160, bg1.center.y+a)];
    a *= 0.9;

    if (a < 0.15 & a > 0 || a > -0.15 & a < 0) [self resetA];
}
#定义kA 3
-(无效)viewDidLoad{
[超级视图下载];
步长=0;
a=kA;
[NSTimer scheduledTimerWithTimeInterval:.04目标:自选择器:@selector(walk)
userInfo:nil repeats:YES];
}
-(void)resetA{//此函数使UIImageView可以上下移动
如果(a>0)a=-kA;
否则a=kA;
steps++;
NSLog(@“%i”,步骤);
}
-(void)walk{//此函数使UIImageView变大并上下移动
如果(a>0)[bg1 setFrame:CGRectMake(0,0,bg1.bounds.size.width+a,
bg1.边界、大小、高度+a)];
else[bg1 setFrame:CGRectMake(0,0,bg1.bounds.size.width-a,
bg1.边界、大小、高度(a)];
[bg1设置中心:CGPointMake(160,bg1.center.y+a)];
a*=0.9;
如果(a<0.15&a>0 | a>-0.15&a<0)[自复位a];
}

A)在你的问题中添加一两张图片来说明你所说的“glitchy”是什么意思,B)制作一个小测试项目供人们下载和查看,这可能是值得的。要求人们创建一个新项目,插入源代码,添加一些图像,然后编译它,等等。要做到这一点,步骤太多了。好的,我会添加一个项目链接,如果我不尊重你们,很抱歉。提示:1)使用计时器而不是定时计时器。2) 使用setCenter和setBounds,而不是setFrame和setCenter。SetFrame(签出)同时设置边界和中心谢谢您设置边界已工作:)