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

标签 ios uiscrollview

我知道这已经发布了大约一百万次,但我无法让这个 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/

相关文章:

ios - 滚动动态 TableView (iOS) 时不再初始化全局变量

ios - 如何创建带圆角的tableview

iphone - 为什么添加对象后 UIScrollView 不会完全滚动?使用 Storyboard、ARC 和 Xcode 4.5.2

ios - UIScrollView - UILabel 如何将内容推到屏幕外

ios - scrollToItem 在我的 CollectionView 中不起作用?

iphone - UILabel 更新在滚动期间停止 UIScrollView

ios - 在 Swift 3 中动态调整 UILabel 的宽度

ios - UIScrollView如何设置ContentInset和ScrollerInset

ios - 读取webView中的HTML元素(_ :decidePolicyFor:decisionHandler:)

swift - 在 UIStackView 中调整 View 的大小以在运行时填充剩余的屏幕大小