在这里,我编写代码以在单击时移动 imageView。我想在第一次单击时执行向上移动,如果再次单击它会返回。这是我的代码:
-(void)gdown
{
if (penview.center.y > 428) penview.center = CGPointMake(penview.center.x, penview.center.y -5);
if(penview.center.x ==428)
{
[movtimer invalidate];
}
}
-(void)buttonmover
{
movtimer=[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(gdown) userInfo:nil repeats:YES];
if(movtimer==nil)
{
movtimer=[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(gdown) userInfo:nil repeats:YES];
}
}
-(void)gdup
{
if (penview.center.y < 480) penview.center = CGPointMake(penview.center.x, penview.center.y +5);
if(penview.center.y ==480)
{
[movtimers invalidate];
}
}
-(void)buttonmovup
{
movtimers=[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(gdup) userInfo:nil repeats:YES];
if(movtimers==nil)
{
movtimers=[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(gdup) userInfo:nil repeats:YES];
}
}
执行点击操作的方法:
-(IBAction)popupview:(id)sender
{
UIButton *button = sender;
if(button.selected) //
{
[self buttonmover];//gooin up
button.selected = false;
}
else
{
[self buttonmovup];//button goin down
button.selected = true;
}
}
它不工作。单击时图像视图会抖动。我应该在这种方法中做出什么改变?