简体   繁体   English

为什么UIViewContentModeScaleScaleAspectFit在UIScrollView内的UIImageView中不起作用? 见所附图片

[英]Why doesn't UIViewContentModeScaleAspectFit work in a UIImageView inside UIScrollView? See Image attached

I can't understand... it was used to work before in other Apps I made with older IOS framework 我不明白...它曾经在我使用较旧的IOS框架制作的其他应用中可以正常工作

Check the code below: 检查以下代码:

If I changed the contentMode to Left it displays the image... 如果我将contentMode更改为Left,它将显示图像...

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    IBOutlet UIScrollView* scrBook;
}

@property (nonatomic, retain) IBOutlet UIScrollView* scrBook;

@end



@synthesize scrBook;

- (void)viewDidLoad
{
    [super viewDidLoad];

    CGRect frame;
    frame.origin.x = 0;
    frame.origin.y = 0;
    frame.size = self.scrBook.frame.size;

    UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];

    //subview.contentMode = UIViewContentModeLeft;
    subview.contentMode = UIViewContentModeScaleAspectFit;

    UIImage *currentImage = [UIImage alloc];
    currentImage = [UIImage imageNamed:@"model.jpg"];

    subview.image = currentImage;

    [self.scrBook addSubview:subview];

    self.scrBook.contentSize
    = CGSizeMake(self.scrBook.frame.size.width * 1, self.scrBook.frame.size.height);
}

UIViewContentModeLeft: UIViewContentModeLeft:

UIViewContentModeLeft

UIViewContentModeScaleAspectFit: UIViewContentModeScaleAspectFit:

UIViewContentModeScaleAspectFit

Updates: My last attempt was to uddate xcode to 4.5.2 and it doesn't work either, frustrating ... 更新:我的最后一次尝试是将xcode uddate到4.5.2,但它也不起作用,令人沮丧...

Not the answer to your problem, just a few optimizations... 不是您问题的答案,只是一些优化...

UIImage *currentImage = [UIImage alloc];
currentImage = [UIImage imageNamed:@"model.jpg"];

There is no need for the first line, just do this: 不需要第一行,只需执行以下操作:

UIImage *currentImage = [UIImage imageNamed:@"model.jpg"];

Also, 也,

self.scrBook.contentSize
= CGSizeMake(self.scrBook.frame.size.width * 1, self.scrBook.frame.size.height);

can just be... 可以只是...

self.scrBook.contentSize = self.srcBook.frame.size;

I found a solution but still don't know the reason, I upgraded my XCode to 4.5.1 to 4.5.2 and still nothing. 我找到了解决方案,但仍然不知道原因,我将XCode从4.5.1升级到了4.5.2,仍然什么也没有。

I duplicated one old project made in an older version of xcode (older than 4.5.1) using the 4.5.2 with the exaclty same code and it worked fine.... 我复制了一个使用4.5.2的旧版本的xcode(早于4.5.1)制作的旧项目,并使用了相同的代码,并且效果很好。

very weird.. I feel bad I took so many hours trying to find a solution... 非常奇怪..我感到很抱歉,我花了很多时间试图找到解决方案...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM