gpt4 book ai didi

ios - UIScrollView SetZoomScale 不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:54:25 28 4
gpt4 key购买 nike

在阅读了一些关于它的其他提示后,我尝试了:
在 ViewController.m 上

DelegateScrollView ScrollView ;

-(void)viewDidLoad
{

[super viewDidLoad];
ScrollView = [[DelegateScrollView alloc] initWithFrame:CGRectMake(0,- self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
ScrollView.delegate = ScrollView;
ScrollView.scrollEnabled = YES;
ScrollView.backgroundColor = [UIColor blackColor ];
ScrollView.maximumZoomScale = 5.0f;
ScrollView.minimumZoomScale = 1.0f;
[self.view addSubview:ScrollView];
[ScrollView setZoomScale:2 animated:YES];

}

DelegateScrollView.h:

@interface ChildDelegateScrollView : UIScrollView <UIScrollViewDelegate>

@end

并且缩放从未发生过,我也在 ViewController.h 中尝试过:@interface ViewController : UIViewController <UIScrollViewDelegate>然后像这样设置委托(delegate) ScrollView.delegate = self;并且不起作用,如何正确设置 ScrollView 的委托(delegate)?

最佳答案

这一行来自UIScrollView class reference似乎是相关的:

For zooming and panning to work, the delegate must implement both viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale:

我能够使用此 UIViewController 代码在 UIScrollView 上获取 UILabel 以进行缩放:

#import "ViewController.h"

@interface ViewController () <UIScrollViewDelegate> {
UIScrollView *_scrollView;
}

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
scrollView.delegate = self;
scrollView.scrollEnabled = YES;
scrollView.backgroundColor = [UIColor blackColor];
scrollView.maximumZoomScale = 5.0f;
scrollView.minimumZoomScale = 1.0f;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height);
[self.view addSubview:scrollView];
_scrollView = scrollView;

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50.0, 50.0, 100.0, 25.0)];
label.backgroundColor = [UIColor grayColor];
label.textAlignment = NSTextAlignmentCenter;
label.text = @"Test";
[_scrollView addSubview:label];
}

- (void)viewDidAppear:(BOOL)animated
{
[_scrollView setZoomScale:4.0 animated:YES];
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return _scrollView.subviews.firstObject;
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{

}

@end

关于ios - UIScrollView SetZoomScale 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21098507/

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