gpt4 book ai didi

ios - 用户最后触摸了哪个标签以及如何将其从 View 中移除

转载 作者:行者123 更新时间:2023-11-28 22:40:07 24 4
gpt4 key购买 nike

我想知道如何知道用户最后触摸了哪个标签以及如何从 View 中删除该特定标签。我知道如何更改所有标签的属性,但我不知道如何找出最后选择的标签。

这就是我向 View 添加标签的方式。

myNewLabel.text =textField.text;
numberOfLabels++;
myNewLabel.tag=numberOfLabels;
[self.view addSubview:myNewLabel];
[shirtBackgroundView addSubview:myNewLabel];
[myNewLabel addGestureRecognizer:panGestureRecognizer];
[myNewLabel addGestureRecognizer:rotateGestureRecognizer];
[myNewLabel addGestureRecognizer:PinchGestureRecognizer];
myNewLabel.userInteractionEnabled=YES;
myNewLabel.backgroundColor=[UIColor clearColor];
[arrayForLabels addObject:myNewLabel];

下面是我如何更改所有标签的颜色。

    for(int i=0;i<numberOfLabels;i++)
{
UILabel *tempLabel = [arrayForLabels objectAtIndex:i];
tempLabel.textColor=[UIColor redColor];
}



-(void)labelMoved:(UIPanGestureRecognizer *)recognizer
{
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];



if (recognizer.state == UIGestureRecognizerStateEnded) {

CGPoint velocity = [recognizer velocityInView:self.view];
CGFloat magnitude = sqrtf((velocity.x * velocity.x) + (velocity.y * velocity.y));
CGFloat slideMult = magnitude / 200;
NSLog(@"magnitude: %f, slideMult: %f", magnitude, slideMult);

float slideFactor = 0.1 * slideMult; // Increase for more of a slide
CGPoint finalPoint = CGPointMake(recognizer.view.center.x + (velocity.x * slideFactor),
recognizer.view.center.y + (velocity.y * slideFactor));
finalPoint.x = MIN(MAX(finalPoint.x, 0), self.view.bounds.size.width);
finalPoint.y = MIN(MAX(finalPoint.y, 0), self.view.bounds.size.height);

[UIView animateWithDuration:slideFactor*2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
recognizer.view.center = finalPoint;
} completion:nil];


}

}

感谢您的任何建议...

最佳答案

为了检测 UIlabels 以捕获点击:

label.userInteractionEnabled = YES;
UIGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecieved:)];
[label addGestureRecognizer:tap];
[tap release];

//对每个附加标签重复当你触摸

-(void) tapRecieved:(UITapGestureRecognizer *)tap{  
currentLabel = (UILabel *) tap.view;
[currentLabel removeFromSuperview];
}

关于ios - 用户最后触摸了哪个标签以及如何将其从 View 中移除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14766769/

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