我似乎无法使用UIViewContentModeScaleAspectFit属性在我的scrollview中缩放我的imageView以适应滚动视图大小。
- (void)loadView {
UIImage* image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.moilum.com/images/atomicongallery/setmenu/setmenu1.jpg"]]];
imageView = [[UIImageView alloc]initWithImage:image];
imageView.contentMode = UIViewContentModeScaleAspectFit;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
UIScrollView* scrollView = [[UIScrollView alloc]initWithFrame:applicationFrame];
[scrollView addSubview:imageView];
scrollView.contentSize = image.size;
scrollView.minimumZoomScale = 0.3;
scrollView.maximumZoomScale = 3.0;
scrollView.clipsToBounds = NO;
scrollView.delegate = self;
self.view = scrollView;
}
我也试过过imageView.contentMode = UIViewContentModeScaleAspectFill。 scrollView.contentmode = UIViewContentModeScaleAspectFill。一切似乎都不起作用:(
任何出路!?
干杯!
答案 0 :(得分:0)
你试过吗,
-(void)loadView
{
CGRect frame = CGRectMake(0, 0, scrollView.frame.size.width, scrolllView.frame.size.height);
imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.image = [UIImage imageNamed:@"yourimage.png"];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[scrollView addSubView:imageView];
scrollView.contentSize = CGSizeMake( imageView.frame.size.width, imageView.frame.size.height);
}
我在iPad上写这段代码我认为这应该有效, 如果您有任何问题,请告诉我。
祝你好运。答案 1 :(得分:0)
如果未在UIScrollViewDelegate上实现- (UIView *)viewForZoomingInScrollView:(UIScrollView *)sView
方法,UIScrollView将不会调整其zoomScale。
像这样的东西
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)sView
{
NSArray *subViews = [sView subviews];
if([subViews count] > 0){
return [subViews objectAtIndex:0];
}
return nil;
}
(但显然也没有设置代表。)