Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.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
Iphone 在ScrollView中移动子视图_Iphone_Ios_Objective C_Uiscrollview_Views - Fatal编程技术网

Iphone 在ScrollView中移动子视图

Iphone 在ScrollView中移动子视图,iphone,ios,objective-c,uiscrollview,views,Iphone,Ios,Objective C,Uiscrollview,Views,所以我有一个滚动视图,其他3个视图作为子视图。使用滚动视图在控制器存储在阵列中的3个子视图之间翻页 - (void)viewDidLoad { [self loadData]; self.uiScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; [self.uiScrollView setPagingEnabled:YES]; [self.uiScrollView setCont

所以我有一个滚动视图,其他3个视图作为子视图。使用滚动视图在控制器存储在阵列中的3个子视图之间翻页

- (void)viewDidLoad
{  
    [self loadData];

    self.uiScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    [self.uiScrollView setPagingEnabled:YES];
    [self.uiScrollView setContentSize:CGSizeMake(self.view.frame.size.width*3, self.view.frame.size.height)];

    self.uiScrollView.delegate = self;


    [self.view addSubview:self.uiScrollView];

    self.uiPhotoCollectionViewControllers = [[NSMutableArray alloc] init];
    int numberOfOtherViews = 3;
    int subViewOffset = 0;

    for (int i = 0; i < numberOfCollectionViews; i++)
    {
        UIViewController* uiViewController = [[UIPhotoCollectionViewController alloc] initWithData:dataArray];
        // add offset to the view of the controller
        [self.uiScrollView addSubview:uiViewController.view];
        [self.uiViewControllers addObject:uiViewController];
        uiViewController.view.frame = CGRectOffset(uiViewController.view.frame,subViewOffset,0.0f);
        subViewOffset = subViewOffset + uiViewController.view.frame.size.width;
    }
-(void)viewDidLoad
{  
[自动加载数据];
self.uiScrollView=[[uiScrollView alloc]initWithFrame:self.view.frame];
[self.uiScrollView设置分页启用:是];
[self.uiScrollView setContentSize:CGSizeMake(self.view.frame.size.width*3,self.view.frame.size.height)];
self.uiScrollView.delegate=self;
[self.view addSubview:self.uiScrollView];
self.uiPhotoCollectionViewControllers=[[NSMutableArray alloc]init];
int numberofotherview=3;
int subViewOffset=0;
对于(int i=0;i

如果稍后我想用第一个视图在滚动视图中间切换视图,我将如何在不移除所有TEH滚动视图子视图并替换它们的情况下执行此操作。

不可能替换,但可以通过在Self.UIVIEW控制器数组中像这样的对象(s/p>)交换对象来实现这一点。

[scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

然后在交换对象后,可以通过遍历整个数组来添加子视图。

我尝试过这样做。可能是哪里出了问题。我只是在删除后将它们重新添加为子视图,然后使用exchangeObjectAtIndex方法切换控制器数组中的控制器。这有意义吗?只需执行在将它们添加为子视图之前更改,而不是在将它们添加为子视图之后更改。我创建了一个单独的方法在控制器数组中交换它们,然后在调用另一个方法后将它们重新添加为子视图以滚动视图。这就是您所说的Gangan吗?您知道为什么不能将它们正确地放回滚动视图吗。我正在对数组中的每个视图控制器进行for循环:UIViewController*UIViewController=[self.uiViewControllers objectAtIndex:I];[self.uiScrollView addSubview:[UIViewController view]];