Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIScrollView赢得';t以子视图的形式在内部滚动_Ios_Uiview_Uiscrollview - Fatal编程技术网

Ios UIScrollView赢得';t以子视图的形式在内部滚动

Ios UIScrollView赢得';t以子视图的形式在内部滚动,ios,uiview,uiscrollview,Ios,Uiview,Uiscrollview,我有一个UIViewController和一个UIScrollView。由于我必须向视图控制器添加多个视图,而滚动视图只是其中之一,因此我尝试将控制器的视图设置为虚拟UIView,并将滚动设置为子视图,如下所示: [self setView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]]; [[self view] setUserInteractionEnabled:NO]; // TDHexMap

我有一个UIViewController和一个UIScrollView。由于我必须向视图控制器添加多个视图,而滚动视图只是其中之一,因此我尝试将控制器的视图设置为虚拟UIView,并将滚动设置为子视图,如下所示:

    [self setView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]];
    [[self view] setUserInteractionEnabled:NO];

    // TDHexMapScrollView inherits from UIViewController
    [self setHexMapScrollView:[[TDHexMapScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]];
    [[self view] addSubview:[self hexMapScrollView]];
这样滚动就不起作用了。将其添加为主视图可使滚动和平移正常工作:

    [self setHexMapScrollView:[[TDHexMapScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]];
    [self setView:[self hexMapScrollView]];
有什么帮助吗?谢谢

不要这样做:

[[self view] setUserInteractionEnabled:NO];

这将禁用视图和所有子视图的交互。这意味着它会忽略触摸事件,并且不会将它们传播到其子视图,这意味着您的scrollview不会获得任何事件。

我的评论没有得到回复,但我想我会向您展示一个如何进行此操作的示例

申报

CGSize scrollSize;
在您的实现中。然后创建滚动视图、视图、标签等

self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, screenFrame.size.width, screenFrame.size.height - self.tabBarController.tabBar.frame.size.height - self.navigationController.navigationBar.frame.size.height)];
self.scrollView.scrollEnabled = YES;
scrollSize.height = self.View1.frame.size.height + self.Label1.frame.size.height + self.Label2.frame.size.height + self.Label3.frame.size.height + self.Label4.frame.size.height + self.Label5.frame.size.height + self.Label6.frame.size.height;
scrollSize.width = screenFrame.size.width;
[self.scrollView setContentSize:scrollSize];
添加到滚动视图

[self.scrollView addSubview:self.View1];
//Repeat for all views / labels / etc
将滚动视图添加到ViewController

[self.view addSubview:self.scrollView];

检查两者是否都有userInteractionEnabled=yes您是否尝试设置
contentInset
滚动视图是否包含所有其他视图?或者您只是试图滚动某个子集?这两种方法我都做了很多次,但对于您可能缺少的内容,我的第一个猜测是
[TDHexMapScrollView setContentSize:要滚动的视图的大小]我后来添加了它作为尝试之一。将其设置为“是”或“否”不会更改非工作行为