作者:Sunny-虫虫 | 来源:互联网 | 2023-09-25 10:44
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 个解决方案