热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

无法获取UIScrollView进行缩放和滚动-Can'tgetaUIScrollViewtozoomandscroll

Iknowthishasbeenpostedaboutamilliontimes,butIcannotforthelifeofmegetthisScrollvi

I know this has been posted about a million times, but I cannot for the life of me get this Scrollview to work how it should. I have followed about four different tutorials and have spent the last two days attempting to fix this, so I really do hope someone can help me through this (if there happens to be another post that fixes my problem that I didn't see, I'm really sorry).

我知道这已被发布了大约一百万次,但我不能为我的生活让这个Scrollview工作应该如何。我已经关注了四个不同的教程并且花了最后两天试图解决这个问题,所以我真的希望有人可以帮我解决这个问题(如果碰巧有另一个帖子修复了我没看到的问题,我真的很抱歉。

I have an Imageview inside of a Scrollview, containing a picture I'd like to be zoomable/scrollable when it's zoomed.

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

In my WDViewController.h file:

在我的WDViewController.h文件中:

#import 

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

@end

And in my WDViewController.m file:

在我的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

Autolayout is disabled, as I noticed that caused problems to other users on Stack Overflow. I made sure that User Interaction and Multiple Touch were enabled in the Storyboard. But when I launch the app in a simulator, it just sits there. No matter how many times I pinch it doesn't zoom. I thought I did everything, but I must have missed a step that I'm just not seeing for some reason. Can anyone give me a hand?

Autolayout被禁用,因为我注意到在Stack Overflow上给其他用户带来了问题。我确保在Storyboard中启用了User Interaction和Multiple Touch。但是当我在模拟器中启动应用程序时,它就在那里。无论我捏多少次它都不会变焦。我以为我做了一切,但我一定错过了一个我原本没有看到的步骤。任何人都可以帮我一把吗?

EDIT: After the comments below, here's the code I have now (for WDViewController.m, .h hasn't changed):

编辑:在下面的评论之后,这是我现在的代码(对于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

EDIT: And after testing it on my phone, it works. Um... okay then, thanks everyone. My simulator just refuses to accept it. How odd.

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

3 个解决方案

#1


2  

View hierarchy in IB:

在IB中查看层次结构:

View hierarchy in IB

The scroll view was dragged and dropped onto the root view and was snapped into place to fill the entire root view. Image view was dragged and dropped onto the scroll view and was snapped into place to fill the entire scroll view.

滚动视图被拖放到根视图上并被捕捉到位以填充整个根视图。图像视图被拖放到滚动视图上并被捕捉到位以填充整个滚动视图。

Attributes for image view in IB:

IB中图像视图的属性:

enter image description here

All source code:

所有源代码:

enter image description here

#2


3  

Just a hunch:

只是一种预感:

To pinch in the iOS Simulator, you have to hold down the option key.

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

#3


1  

did you add the image view to scrollview's subview? [self.scrollView addSubView:self.img_wd]

你是否将图像视图添加到scrollview的子视图? [self.scrollView addSubView:self.img_wd]


推荐阅读
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文介绍了Python语言程序设计中文件和数据格式化的操作,包括使用np.savetext保存文本文件,对文本文件和二进制文件进行统一的操作步骤,以及使用Numpy模块进行数据可视化编程的指南。同时还提供了一些关于Python的测试题。 ... [详细]
  • 带添加按钮的GridView,item的删除事件
    先上图片效果;gridView无数据时显示添加按钮,有数据时,第一格显示添加按钮,后面显示数据:布局文件:addr_manage.xml<?xmlve ... [详细]
  • vue使用
    关键词: ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • HTML学习02 图像标签的使用和属性
    本文介绍了HTML中图像标签的使用和属性,包括定义图像、定义图像地图、使用源属性和替换文本属性。同时提供了相关实例和注意事项,帮助读者更好地理解和应用图像标签。 ... [详细]
  • 本文讨论了如何在codeigniter中识别来自angularjs的请求,并提供了两种方法的代码示例。作者尝试了$this->input->is_ajax_request()和自定义函数is_ajax(),但都没有成功。最后,作者展示了一个ajax请求的示例代码。 ... [详细]
  • iOS Swift中如何实现自动登录?
    本文介绍了在iOS Swift中如何实现自动登录的方法,包括使用故事板、SWRevealViewController等技术,以及解决用户注销后重新登录自动跳转到主页的问题。 ... [详细]
  • IOS开发之短信发送与拨打电话的方法详解
    本文详细介绍了在IOS开发中实现短信发送和拨打电话的两种方式,一种是使用系统底层发送,虽然无法自定义短信内容和返回原应用,但是简单方便;另一种是使用第三方框架发送,需要导入MessageUI头文件,并遵守MFMessageComposeViewControllerDelegate协议,可以实现自定义短信内容和返回原应用的功能。 ... [详细]
  • 本文介绍了如何使用vue-awesome-swiper组件,包括在main.js中引入和使用swiper和swiperSlide组件,以及设置options和ref属性。同时还介绍了如何在模板中使用swiper和swiperSlide组件,并展示了如何通过循环渲染swipes数组中的数据,并使用picUrl属性显示图片。最后还介绍了如何添加分页器。 ... [详细]
  • Android源码中的Builder模式及其作用
    本文主要解释了什么是Builder模式以及其作用,并结合Android源码来分析Builder模式的实现。Builder模式是将产品的设计、表示和构建进行分离,通过引入建造者角色,简化了构建复杂产品的流程,并且使得产品的构建可以灵活适应变化。使用Builder模式可以解决开发者需要关注产品表示和构建步骤的问题,并且当构建流程发生变化时,无需修改代码即可适配新的构建流程。 ... [详细]
  • SpringBoot简单日志配置
     在生产环境中,只打印error级别的错误,在测试环境中,可以调成debugapplication.properties文件##默认使用logbacklogging.level.r ... [详细]
author-avatar
Sunny-虫虫
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有