我的应用中有一个包含UIImageView的子视图。用户可以触摸此子视图并移动它。我有一些我想要的UILabel"坚持"或者使用子视图进行分组,以便它们随之移动。我想知道该怎么做? 这是我将标签添加到子视图的地方:
- (void)viewDidLoad
{
[super viewDidLoad];
//Decrease the site of root CALayer of the view and give it round corners
self.view.layer.backgroundColor = [UIColor orangeColor].CGColor;
self.view.layer.cornerRadius = 10.0;
self.view.layer.masksToBounds = YES;
self.view.layer.frame = CGRectInset(self.view.layer.frame, 40, 40);
//check if the background is from the photo library and create a sublayer for the semi transparent white badge and a textsublayer for the countdown labels. Also hide the regular view labels
NSString *path = [_occasion imagePath];
if (path != nil && [path hasPrefix:@"ass"])
{
//Make a subview with a UIImageView inside for the badge
CGRect badgeRect = CGRectMake(32, 13, 236, 222);
UIView *badge = [[UIView alloc] initWithFrame:badgeRect];
imageView = [[UIImageView alloc]initWithFrame:[badge frame]];
[imageView setImage:[UIImage imageNamed:@"badge.png"]];
[badge addSubview:imageView];
[self.view addSubview:badge];
/*[self.view bringSubviewToFront:countDownLabel];
[self.view bringSubviewToFront:daysLabel];
[self.view bringSubviewToFront:hoursLabel];
[self.view bringSubviewToFront:minutesLabel];
[self.view bringSubviewToFront:secondsLabel];
[self.view bringSubviewToFront:daysName];
[self.view bringSubviewToFront:hoursName];
[self.view bringSubviewToFront:minutesName];
[self.view bringSubviewToFront:secondsName];*/
[badge addSubview:countDownLabel];
[badge addSubview:daysLabel];
[badge addSubview:hoursLabel];
[badge addSubview:minutesLabel];
[badge addSubview:secondsLabel];
[badge addSubview:daysName];
[badge addSubview:hoursName];
[badge addSubview:minutesName];
[badge addSubview:secondsName];
//more code for recognizing the touches on the subview
答案 0 :(得分:1)
只需将它们放在UIImageView上,它们就会随之移动。
答案 1 :(得分:1)
您可以获取子视图的位置,并根据该位置更改标签的位置。