【发布时间】:2014-05-29 13:28:13
【问题描述】:
我有问题。
简而言之:CGRectIntersectsRect(object1.frame, object2.frame) 放在 UIViewController 中不适用于在不同类(Class1 和 Class2)中创建的 object1 和 object2。我只能更改它们的坐标,例如object1.center.x 和object1.frame.size.width = 0(我想这就是CGRectIntersection 函数不起作用的原因)。这些对象只是相互穿过。
据我了解,它可能与协议/委托有关,但我没有找到任何足够的信息来解决我的情况。
Platform.m(我在 ViewController 中创建平台的类)
@implementation Platform
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
platformView = [[UIImageView alloc]initWithFrame:frame];
platformView.image = [UIImage imageNamed:@"platform.png"];
[self addSubview:platformView];
}
return self;
}
ViewController.m(@interface中有Platform *platform; Kelvin *kelvin;)
-(void)addPlatform
{
platform = [[Platform alloc]initWithFrame:CGRectMake(initialPlatformX, (500 - arc4random()%200), 200, 10)];
[self.view addSubview:platform];
}
**if (!CGRectIntersectsRect(kelvin.frame, platform.frame)) {
NSLog(@"%f", platform.frame.size.width);
}**
【问题讨论】:
-
顺便说一句,你没有显示
kelvin的创建。它是platform的同一视图的子视图吗?如果它们不是同一视图的子视图,则必须将框架转换为相同的坐标系。
标签: ios objective-c uiimageview cgrect