将UIscrollView安排回来

时间:2013-05-06 15:41:33

标签: ios xcode uiscrollview

也许是一个巨大的菜鸟问题,但我似乎无法弄明白,即使经过一段时间的谷歌搜索,我无法找到在导航栏下方安排滚动视图。

我的代码:

    - (void)loadView {

    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    scroll.backgroundColor = [UIColor blackColor];
    scroll.delegate = self;
    image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Plattegrond DeFabrique schematisch.png"]];
    scroll.contentSize = image.frame.size;
    [scroll addSubview:image];

    scroll.minimumZoomScale = scroll.frame.size.width / image.frame.size.width;
    scroll.maximumZoomScale = 2.0;
    [scroll setZoomScale:scroll.minimumZoomScale];

    self.view = scroll;

}

enter image description here

enter image description here

3 个答案:

答案 0 :(得分:0)

尝试在superview后面插入视图或尝试sendSubviewToBack。

[[self.view superview] insertSubview:scroll belowSubview:self.view];

[self.view sendSubviewToBack:scroll];

听起来你只想将滚动视图添加到self.view中。按照其他答案建议并从self.view框架创建scrollView,然后将其添加到self.view。

UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame]; // Thilina
[self.view addSubview:scroll];

答案 1 :(得分:0)

您可以在创建ScrollView时简单地使用self.view的框架。这将解决您的问题。

- (void)loadView {

    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
    scroll.backgroundColor = [UIColor blackColor];
    scroll.delegate = self;
    image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Plattegrond DeFabrique schematisch.png"]];
    scroll.contentSize = image.frame.size;
    [scroll addSubview:image];

    scroll.minimumZoomScale = scroll.frame.size.width / image.frame.size.width;
    scroll.maximumZoomScale = 2.0;
    [scroll setZoomScale:scroll.minimumZoomScale];

    [self.view addSubView:scroll]; //MarkM

}

答案 2 :(得分:0)

由于在分配UIScrollView时传递[UIScreen mainScreen]的帧,因此UIScrollView的大小与UINavigation重叠。替换为

UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame];

也不是用scrollView替换self.view,而是尝试在self.view上添加scrollView作为子视图

[self.view addSubview:scrollView];

viewDidLoad

中执行以下任务

希望它会对你有所帮助。