此代码的目标是自动创建一个对象并为其设置动画以在屏幕上移动。一旦它在 120 处达到 x,则将其删除。我面临的问题是我无法从数组中的对象中获取框架和 x 值。这是我的代码,有什么建议吗?
- (void)AddRight{
Bullets= [[NSMutableArray alloc] init];
CGRect frame = CGRectMake(480, 180, 60, 55);
Bullets = [[UIImageView alloc] initWithFrame:frame];
Bullets.image=[UIImage imageNamed:@"Bullet.png"];
[self.view addSubview:Bullets];
[Bullets addObject:theBullet];
for (int x = 0; x < [Bullets count]; x++) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[theBullet setFrame:CGRectMake(265, 180, 60, 55)];
[UIView commitAnimations];
}
并且检测在这里:
for (int x = 0; x < [Bullets count]; x++) {
NSObject *bull = [[LeftBees objectAtIndex:x]];
CGRect frame = bull.frame;
if (frame.origin.x>120) {
[bull removeFromSuperview];
}
}
“CGRect 框架 = referal.frame;” 有错误说“属性框架不是 NSObject 的一部分”