我正在尝试使用以下方法以编程方式移动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);
}
当该方法被调用时,NSLogs显示变量currentBeat正在按其应有的方式递增,并且playbackLine (my UIView)的帧似乎正在按其应有的方式移动。但是,屏幕上的对象不会移动。我还尝试了设置边界和中心,而不是帧,所有这些都有类似的结果。我也尝试使用动画而不是设置帧,但没有用。
要使屏幕上的图像显示变化的帧,我还需要做些什么吗?
发布于 2012-08-01 16:56:23
我猜你是在一个循环中调用那个方法?在代码执行完成之前,iOS不会重新绘制屏幕。你不能像这样循环并看到迭代的结果。
要使视图具有动画效果,您应该使用UIKit提供的本机支持。特别是,请查看the Animations section in the UIView class reference。
发布于 2012-08-01 16:56:33
尝尝这个
[UIView animateWithDuration:0.3
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{
datePickerView.frame = imageFrame;
}
completion:^(BOOL finished){
self.datePickerViewFlag = NO;
}];
https://stackoverflow.com/questions/11763913
复制相似问题