gpt4 book ai didi

ios - Xcode:标签制作错误

转载 作者:行者123 更新时间:2023-11-29 11:14:30 25 4
gpt4 key购买 nike

    - (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.
}

错误是:使用了未声明的标识符“window”

最佳答案

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

- (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;
}

另请注意,您应该获取图像的 super View 位置,而不是图像本身。

关于ios - Xcode:标签制作错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10074826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com