【问题标题】:CGRectMake Does not move image (Sometimes)CGRectMake 不移动图像(有时)
【发布时间】:2014-10-21 22:11:52
【问题描述】:

当点击我的应用程序中的图像并且图像位于顶部时,图像将始终完美地向下移动。但是当图像位于底部时,有时图像不会向上移动。即使它不移动,该进程仍在运行,并且它记录下来就好像它在顶部一样。我尝试了所有我知道该怎么做的方法,但是您发现有什么问题吗?谢谢!!

- (void )imageTapped:(UITapGestureRecognizer *) gestureRecognizer 
{
    NSLog(@"imageTapped");

    [UIView beginAnimations:@"move" context:nil];
    [UIView setAnimationDuration:0.3];

    if (self.imgV.frame.origin.y == 20) {

        NSLog(@"Top");

        upOrDown = @"1";


        self.invalidateTheTimer = @"";
        timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];

        self.imgV.frame=CGRectMake(0, self.view.frame.size.height-self.imgV.frame.size.height, self.imgV.frame.size.width, self.imgV.frame.size.height);
        self.vBottom.frame=CGRectMake(0, self.imgV.frame.origin.y+self.imgV.frame.size.height, self.vBottom.frame.size.width, self.vBottom.frame.size.height);

    } else if (self.imgV.frame.origin.y >= 507) {

        NSLog(@"Bottom");


        self.imgV.frame=CGRectMake(0, 20, self.imgV.frame.size.width, self.imgV.frame.size.height);
        self.vBottom.frame=CGRectMake(0, self.imgV.frame.origin.y+self.imgV.frame.size.height, self.vBottom.frame.size.width, self.vBottom.frame.size.height);



        [hour setText:@""];
        [minute setText:@""];
        [second setText:@""];

        [timer invalidate];
        self.invalidateTheTimer = @"INVALIDATE";



    }

        NSLog(@"%f", self.imgV.frame.origin.y);
    [UIView commitAnimations];

}

【问题讨论】:

    标签: objective-c image logging move cgrectmake


    【解决方案1】:

    考虑到你还没有发布你的整个代码,很难弄清楚到底出了什么问题,但是看看你造成的混乱,我建议你看看block based animations,它应该可以简化你正在尝试的事情完成。

    另外,如果我不得不猜测的话,我会说问题出在你的计时器上,它调用的任何方法都可能会干扰你的动画。

    【讨论】:

      猜你喜欢
      • 2012-07-14
      • 1970-01-01
      • 2012-10-22
      • 2018-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多