1
    - (void)viewDidLoad
{
    CGRect frame = CGRectMake(20, 45, 140, 21);
    UILabel *label = [[UILabel alloc] initWithFrame:frame];

    [window addSubview:label];
    [label setText:@"Hello world"];
    [label release];

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

错误是:使用下划线标识符“窗口”

4

1 回答 1

1

您可以设置每个字母的标签属性,并在 touchesMoved 上检查它们。UIImageView

- (void)touchesMoved:(NSSet*)touches withEvent: (UIEvent*)event{

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view.superview];

    switch (touch.view.tag) {
        case 0:
            a.center=location;
            break;
        case 1:
            b.center=location;
            break;
        case 3:
            c.center=location;
            break;
    }
}

编辑

使用@beryllium 的评论:

- (void)touchesMoved:(NSSet*)touches withEvent: (UIEvent*)event{

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view.superview];
    touch.view.center = location;
}

另请注意,您应该获取图像的超级视图位置,而不是从图像本身。

于 2012-04-09T14:51:17.820 回答