【问题标题】:xcode 5 horizontal scroll doesn't workxcode 5水平滚动不起作用
【发布时间】:2014-03-07 20:55:17
【问题描述】:

谁能帮我处理这段代码?只是它不起作用,就像我尝试过的所有垂直滚动一样。我开始认为我的 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

【问题讨论】:

  • 你想做什么?你想滚动图片吗?
  • 是的,我按照教程来水平滚动图像。我一步一步跟着它,但我的模拟器没有滚动。

标签: uiscrollview uiimageview horizontal-scrolling


【解决方案1】:

设置UIImageView 后,需要将scrollViewcontentSize 设置为imageViewimageView,所以,如下所示:

[scroll setContentSize:imageview.frame.size];

【讨论】:

  • 首先,Xcode 建议我将“UIScrollView”和“imageView”中的“scrollview”更改为“imageview”。另外,在“setContentSize”上,我遇到了一个问题:不知道选择器 SetContentSize 的类方法。
  • 好吧,我只是把通用对象名称放在那里。你应该使用你自己的名字。与setContentSize 一样,您可以使用scroll.contentSize
  • 好吧,我是个笨蛋。滚动时我没有单击鼠标按钮,我累了...感谢您的帮助! :-)
猜你喜欢
  • 2017-01-07
  • 2013-06-29
  • 2012-08-13
  • 1970-01-01
  • 2013-11-11
  • 2019-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多