Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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:如何在启用分页的情况下滚动到下一页?_Ios_Uiscrollview_Paging_Uiviewanimation - Fatal编程技术网

Ios UIScrollView:如何在启用分页的情况下滚动到下一页?

Ios UIScrollView:如何在启用分页的情况下滚动到下一页?,ios,uiscrollview,paging,uiviewanimation,Ios,Uiscrollview,Paging,Uiviewanimation,我有一个启用分页的滚动视图 我想通过编程方式滚动到下一页。我的代码 CGRect newRect = self.scrollView.bounds; newRect.origin = CGPointMake(self.scrollView.contentOffset.x + newRect.size.width, 0); [self.scrollView scrollRectToVisible:newRect

我有一个启用分页的滚动视图

我想通过编程方式滚动到下一页。我的代码

    CGRect newRect = self.scrollView.bounds;
    newRect.origin = CGPointMake(self.scrollView.contentOffset.x + newRect.size.width, 0);

    [self.scrollView scrollRectToVisible:newRect
                                animated:YES];
但实际情况是,滚动开始,然后在完成80~90%时,滚动回到初始页面。它更像是“转到(n+1)并立即返回到n”的动画,而不是“转到(n+1)”的动画


问题可能是
scrollRectToVisible
和分页模式之间的一些交互。

这太简单了,我给你一个方法,直接使用它只在头文件中生成对象

@property (weak, nonatomic) IBOutlet UIScrollView *scrollViewImages;
创建方法loadImages之后

-(void)loadImages
{

_scrollViewImages.contentSize = CGSizeMake(arrayAdImages.count*_scrollViewImages.frame.size.width,0);
_scrollViewImages.pagingEnabled=YES;

if(arrayAdImages.count>0)
{

    int xOrigin = 0;

    for(int i =0; i<[arrayAdImages count]; i++)

    {
        NSString*img=[arrayAdImages objectAtIndex:i];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = i;


        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
        button.frame = CGRectMake(xOrigin, 0, 768  ,768);
        }
        else{
        button.frame = CGRectMake(xOrigin, 0, 320  ,320);

        }
        NSString *image=[NSString stringWithFormat:@"%@",img];
         image= [image stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSLog(@"image url tesing %@",image);
        [button setBackgroundImageForState:UIControlStateNormal withURL:[NSURL URLWithString:image]];

        if (i==0) {
            [imgUrlForSharing setImageWithURL:[NSURL URLWithString:image]];
        }


        [_scrollViewImages addSubview:button];
        xOrigin = xOrigin + _scrollViewImages.frame.size.width;



         button.contentMode=UIViewContentModeScaleAspectFill;

    }
}
double delayInSeconds = 1.3;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [[_scrollViewImages viewWithTag:1356] removeFromSuperview];
});

_scrollViewImages.showsHorizontalScrollIndicator=false;
_scrollViewImages.showsVerticalScrollIndicator=false;
}
-(无效)加载图像
{
_scrollViewImages.contentSize=CGSizeMake(arrayAdImages.count*\u scrollViewImages.frame.size.width,0);
_scrollViewImages.PaginEnabled=是;
如果(arrayAdImages.count>0)
{
int-xOrigin=0;
对于(int i=0;i
(currentPage+1)*滚动.frame.width;
将其设置为
内容偏移量