문제

who can help me with this code? Simply it doesn't work, same as ALL I have tried for vertical scrolling. I'm starting to think that my Xcode emulator has something wrong. Here's the code:

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 30, 300, 400)];
[self.view addSubview:scroll];
[scroll setBackgroundColor:[UIColor redColor]];
{

    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1222, 400)];
    [imageview setImage:[UIImage imageNamed:@"panorama_orizzonte_medio_big.jpg"]];
    [scroll addSubview:imageview];
    [self.view addSubview:scroll];
}
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
도움이 되었습니까?

해결책

After you set the UIImageView, you need to set the scrollView's contentSize to that of your imageView's, so, something like this:

[scroll setContentSize:imageview.frame.size];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top