gpt4 book ai didi

ios - UIScrollView 为 self.view 添加缩放

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

我需要缩放 View 中的所有对象,但丢失了对象的位置(UIButton)

- (void)viewDidLoad
{

CGRect scrollViewFrame = CGRectMake(0, 0, 320, 460);
scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
scrollView.delegate = self;

scrollView.minimumZoomScale = 1;
scrollView.maximumZoomScale = 4.0;


[self.view addSubview:scrollView];
CGSize scrollViewContentSize = CGSizeMake(640, 800);
[scrollView setContentSize:scrollViewContentSize];



NSMutableArray *datos = [[NSMutableArray alloc]initWithObjects:@"ob1",@"ob2",@"ob3",@"ob4", nil];

for (int i = 0; i < [datos count]; i++) {


UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod)
forControlEvents:UIControlEventTouchUpInside];
button.frame = CGRectMake(100, 100*i, 70, 70);
button.tag = i;
[button setTitle: @"Line1" forState: UIControlStateNormal];
button.hidden= NO;
[scrollView addSubview:button];
}



}


-(void)aMethod{

}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{

return scrollView.superview;
}

最佳答案

您应该设置一个 subview 容器并将其作为 viewForZoomingInScrollView 传递。

subview 应包含您的按钮:

self.buttonSubview = [[UIView alloc] initWithFrame:...];
...
[buttonSubview addSubview:button];
...
[scrollView addSubview:buttonSubview];

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return self.buttonSubview;
}

关于ios - UIScrollView 为 self.view 添加缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18769480/

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