gpt4 book ai didi

ios - 无法让 UIScrollView 进行缩放和滚动

转载 作者:行者123 更新时间:2023-12-01 17:41:03 24 4
gpt4 key购买 nike

我知道这已经发布了大约一百万次,但我无法让这个 Scrollview 以它应该的方式工作。我已经遵循了大约四个不同的教程,并且在过去的两天里一直在尝试解决这个问题,所以我真的希望有人能帮助我解决这个问题(如果碰巧有另一个帖子解决了我没有看到的问题,我真的很抱歉)。

我在 Scrollview 中有一个 Imageview,其中包含一张我希望在缩放时可缩放/可滚动的图片。

在我的 WDViewController.h 文件中:

#import <UIKit/UIKit.h>

@interface WDViewController : UIViewController <UIScrollViewDelegate>
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@property (nonatomic, retain) IBOutlet UIImageView *img_wd;

@end

在我的 WDViewController.m 文件中:
#import "WDViewController.h"

@implementation WDViewController

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

- (void)viewDidLoad
{
[super viewDidLoad];
self.scrollView.minimumZoomScale=0.5;
self.scrollView.maximumZoomScale=6.0;
self.scrollView.delegate=self;
self.scrollView.contentSize=CGSizeMake(1280, 960);
self.scrollView.scrollEnabled = true;
self.scrollView.userInteractionEnabled = true;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

自动布局被禁用,因为我注意到这给 Stack Overflow 上的其他用户带来了问题。我确保在 Storyboard 中启用了用户交互和多点触控。但是当我在模拟器中启动应用程序时,它就坐在那里。无论我捏多少次它都不会缩放。我以为我做了所有的事情,但我一定错过了一个我只是因为某种原因没有看到的步骤。谁能帮我一把?

编辑:在下面的评论之后,这是我现在拥有的代码(对于 WDViewController.m,.h 没有改变):
#import "WDViewController.h"

@implementation WDViewController

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

- (void)viewDidLoad {
[super viewDidLoad];
[self.scrollView addSubview:self.img_wd];
self.img_wd.frame = CGRectMake(0, 0, 1280, 960);
self.scrollView.minimumZoomScale=0.5;
self.scrollView.maximumZoomScale=6.0;
self.scrollView.delegate=self;
self.scrollView.contentSize=CGSizeMake(1280, 960);
self.scrollView.scrollEnabled = true;
self.scrollView.userInteractionEnabled = true;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

编辑:在我的手机上测试后,它可以工作。嗯……好吧,谢谢大家。我的模拟器只是拒绝接受它。多么奇怪。

最佳答案

只是一种预感:

要捏入 iOS 模拟器,您必须按住选项键。

关于ios - 无法让 UIScrollView 进行缩放和滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19645924/

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