gpt4 book ai didi

objective-c - Objective-C : Create a new View in touches end

转载 作者:行者123 更新时间:2023-11-28 22:52:37 26 4
gpt4 key购买 nike

我正在尝试编写一个程序,每次我的触摸结束时,都会出现另一个 UIView,它使用循环显示我想要的 UIView。如何在触摸端设置 UIView 循环?或者我应该在 viewDidLoad 中创建它并在触摸结束时调用它?

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event//upon leaving
{
UITouch *touch = [touches anyObject];

for (int i=0; i < 100; i++) {
UIImageView *layerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[layerView setAlpha:.05];
[self.view addSubview:layerView];
}
}

希望大家能帮帮我..

最佳答案

如果您想在每次点击后添加一个 View ,则不需要 for 循环。就这样

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event//upon leaving
{
UITouch *touch = [touches anyObject];

UIImageView *layerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[layerView setAlpha:.05];

// If you just want to add a line, add another uiview would the easiest way. For example:
UIView *line = [UIView alloc] initWithFrame:CGRectMake(0, layerView.center.y, layerView.frame.size.width, 1)];
line.backgroundColor = [UIColor blackColor];
[layerView addSubview:line];

[self.view addSubview:layerView];
}

当然,你也可以子类化一个UIView,然后在里面画任何你想画的东西

- (void)drawRect:(CGRect)rect

关于objective-c - Objective-C : Create a new View in touches end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11571681/

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