Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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
Objective c 移动视图_Objective C_Ios_Animation_Uiview - Fatal编程技术网

Objective c 移动视图

Objective c 移动视图,objective-c,ios,animation,uiview,Objective C,Ios,Animation,Uiview,我尝试使用以下方法以编程方式移动UIView: -(void)animatePlaybackLine: (int) currentBeat{ CGRect newFrame = CGRectMake(currentBeat*eighthNoteWidth, 0, eighthNoteWidth, 320); [playbackLine setFrame:newFrame]; NSLog(@"Line animated to %i", currentBeat); N

我尝试使用以下方法以编程方式移动UIView:

-(void)animatePlaybackLine: (int) currentBeat{
    CGRect newFrame = CGRectMake(currentBeat*eighthNoteWidth, 0, eighthNoteWidth, 320);
    [playbackLine setFrame:newFrame];
    NSLog(@"Line animated to %i", currentBeat);
    NSLog(@"New frame origin %f", playbackLine.frame.origin.x);
}
调用该方法时,NSlog显示变量currentBeat正在按应有的方式递增,playbackLine的帧(my UIView)似乎正在按应有的方式移动。但是,屏幕上的对象不会移动。我还尝试设置边界和中心,而不是框架,它们都有类似的结果。我还尝试使用动画而不是设置帧,但没有效果


我还应该做些什么来让屏幕上的图像显示变化的画面

我猜你在循环中调用那个方法?在代码执行完成之前,iOS不会重新绘制屏幕。您不能像这样循环并看到迭代结果

要设置视图动画,应使用UIKit提供的本机支持。特别是,请查看。

试试这个

    [UIView animateWithDuration:0.3
                      delay:0.0
                    options: UIViewAnimationCurveEaseOut
                 animations:^{
                     datePickerView.frame = imageFrame;
                 } 
                 completion:^(BOOL finished){
                     self.datePickerViewFlag = NO;
                 }];

您确定调用此函数时,
playbackLine
不是
nil
?您是通过
NSTimer
回调调用
animatePlaybackLine:
,还是以其他方式调用?感谢您的回复--playbackLine绝对不是零。animatePlaybackLine:在另一个使用NSTimer的类中的while循环中被调用。这回答了你的问题吗?我怀疑这可能是重新绘制屏幕的问题。我尝试过使用动画:[UIView animateWithDuration:1动画:^{playbackLine.frame=newFrame;}];但它给了我同样的结果。是否有方法告诉viewController重画?如果使用普通动画方法,则不必告诉view controller重画。你已经把线圈取出来了,对吗?你不需要计时器、循环或类似的东西。本机动画支持为您解决所有问题。手动操作是错误的。我最初担心使用动画的原因是因为我需要视觉效果与音频播放精确同步,但似乎唯一的方法是使用动画,所以我就这样做。谢谢你的帮助。这给了我同样的结果——UIView认为它的框架在改变,但它在显示器中没有移动。