【发布时间】:2009-01-16 21:19:38
【问题描述】:
我正在开发一个 iPhone 应用程序,它根据加速度计在其他 UIView 层之间移动 UIView 层。
如果最顶层是根据加速度计移动的那一层,那没问题。如果我在它上面添加一个 UIView ,移动就会非常延迟。如果我在其上添加第二个 UIView,则移动停止。
updateInterval 为 60,我正在使用 UIView 的 drawAtPoint: 方法来移动图层。
我的问题:是否需要启用 UIView 属性(例如 opaque、clipsToBounds 等)才能使夹层 UIView 发生基于加速度计的准确移动?
提前感谢您提供的任何帮助。
更新:
底层是不透明的,上面的层是透明的PNG。
我在访问 UIView 的 frame 属性时遇到了困难。这是我的Object2D 课程中的一些代码:
- (id)initWithImage:(NSString*)imageName
{
if (self = [super init])
{
position = [[Point2D alloc] init];
vector = [[Vector2D alloc] init];
imagePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
myImageObj = [[UIImage alloc] initWithContentsOfFile:imagePath];
size.width = myImageObj.size.width;
size.height = myImageObj.size.height;
}
return self;
}
这是从 ViewController 类调用的类的原始 draw: 方法:
- (void)draw
{
[myImageObj drawAtPoint:CGPointMake( position.X, position.Y ) ];
[ self setNeedsDisplay ];
}
我尝试了各种方法来访问框架属性,但无济于事:
myImageObj.frame = CGRectMake(position.X, position.Y, size.width, size.height);
myImageObj.CGImage.frame.y = position.Y;
查看 API 文档表明第一种方法可行,但没有。
你知道如何访问 UIView 的 frame 属性吗?
提前致谢。
【问题讨论】:
标签: iphone cocoa-touch