Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.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/5/objective-c/24.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 附加UIView';s到UIScrollView的顶部_Iphone_Objective C_Ios_Ipad - Fatal编程技术网

Iphone 附加UIView';s到UIScrollView的顶部

Iphone 附加UIView';s到UIScrollView的顶部,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,例如,在Tweetbot的iPhone应用程序中。当您打开应用程序并收到新的推文时,它将被附加到UIScrollView的顶部,而您看到的当前推文没有刷新。我怎样才能达到同样的效果?。假设我有一个UIScrollView,其中UIView从原点10,10添加到UIScrollView 然后我下载了一些东西,我想把它定在10,10。。所以我基本上需要把这个旧东西移到10,10的右边?如果我这样做了,那么在移动过程中,用户会看到它移动,这不是我想要的效果。在Tweetbot的应用程序中,似乎没有任何

例如,在Tweetbot的iPhone应用程序中。当您打开应用程序并收到新的推文时,它将被附加到UIScrollView的顶部,而您看到的当前推文没有刷新。我怎样才能达到同样的效果?。假设我有一个UIScrollView,其中UIView从原点10,10添加到UIScrollView

然后我下载了一些东西,我想把它定在10,10。。所以我基本上需要把这个旧东西移到10,10的右边?如果我这样做了,那么在移动过程中,用户会看到它移动,这不是我想要的效果。在Tweetbot的应用程序中,似乎没有任何变化,只是你将区域扩大到10,10以上,并在那里添加新的内容

我该怎么做


基本上,我想在UIScrollView中实现InsertRowatineXpath。

如果设置
contentOffset
而不设置动画,则不会出现可见的滚动动画。因此,如果新视图的高度为200点,您可以将新视图的原点设置为(10,10),将旧视图的原点设置为(10210),并将滚动视图的
contentOffset
设置为(10210),您应该可以达到您想要的效果。您还需要增加滚动视图的
contentSize
,使其足以容纳所包含的所有内容。

将以这种方式重申这个问题:如何将内容添加到UIScrollView的顶部,而不移动已经存在的内容(相对于其当前偏移量)

如果这是一个正确的问题,正确的答案是按照您的建议进行添加和下移,但随后滚动与添加内容相同的高度,从而产生旧内容没有移动的错觉

- (void)insertRowAtTop {

    // not showing insert atIndexPath because I don't know how you have your subviews indexed
    // inserting at the top, we can just shift everything down.  you can extend this idea to
    // the middle but it requires that you can translate from rows to y-offsets to views

    // shift everything down
    for (UIView *view in self.scrollView.subviews) {
        if ([view isKindOfClass:[MyScrollViewRow self]]) {
            MyScrollViewRow *row = (MyScrollViewRow *)view;          // all this jazz so we don't pick up the scroll thumbs
            row.frame = CGRectOffset(row.frame, 0.0, kROW_HEIGHT);   // this is a lot easier if row height is constant
        }
    }
    MyScrollViewRow *newRow = [[MyScrollViewRow alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,kROW_HEIGHT)];
    // init newRow
    [self.scrollView addSubview:newRow];

    // now for your question.  scroll everything so the user perceives that the existing rows remained still
    CGPoint currentOffset = self.scrollView.contentOffset
    self.scrollView.contentOffset = CGPointMake(currentOffset.x, currentOffset.y + kROW_HEIGHT);
}