我正在尝试使用以下方法以编程方式移动 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(我的 UIView)的框架似乎在按应有的方式移动。但是,屏幕上的对象并没有移动。我也试过设置边界和中心而不是框架,它们都有相似的结果。我也尝试使用动画而不是设置框架,但无济于事。
我还应该做些什么来让屏幕上的图像显示不断变化的框架吗?
最佳答案
我猜你是在循环中调用那个方法?在您的代码执行完毕之前,iOS 不会重绘屏幕。您不能像这样循环并查看迭代结果。
要为 View 设置动画,您应该使用 UIKit 为您提供的原生支持。特别是,查看 the Animations section in the UIView class reference .
关于objective-c - 移动 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11763913/