xcode 5水平滚动不起作用

时间:2014-03-07 20:55:17

标签: uiscrollview uiimageview horizontal-scrolling

谁可以帮我这个代码?简单地说它不起作用,就像我尝试过的垂直滚动一样。我开始认为我的Xcode模拟器出了问题。这是代码:

@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

1 个答案:

答案 0 :(得分:0)

设置UIImageView后,您需要将scrollView的{​​{1}}设置为contentSize的{​​{1}},所以,如下所示:

imageView