Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.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 如何在UIscrollView中以不同方式增加每个页面的高度_Iphone_Ios_Ipad_Cocoa Touch - Fatal编程技术网

Iphone 如何在UIscrollView中以不同方式增加每个页面的高度

Iphone 如何在UIscrollView中以不同方式增加每个页面的高度,iphone,ios,ipad,cocoa-touch,Iphone,Ios,Ipad,Cocoa Touch,我在单uiscrollView中有四个页面,并且已启用分页。每个页面可能有不同的高度,我试图在ScrollViewDiEndDecreating委托中增加scrollview的内容大小,但这对我没有帮助 有谁能建议如何在每个页面中以不同的方式增加scrollview的contentsize 提前谢谢 这是不可能的,内容大小是滚动视图的边界,它是一个矩形,如何为每个页面更改?为什么不缩放页面,使其大小相同,并使用缩放功能?我认为您无法在本地实现这一点。但是,您可以尝试禁用分页并手动执行 有一种非常

我在单uiscrollView中有四个页面,并且已启用分页。每个页面可能有不同的高度,我试图在ScrollViewDiEndDecreating委托中增加scrollview的内容大小,但这对我没有帮助

有谁能建议如何在每个页面中以不同的方式增加scrollview的contentsize


提前谢谢

这是不可能的,内容大小是滚动视图的边界,它是一个矩形,如何为每个页面更改?为什么不缩放页面,使其大小相同,并使用缩放功能?

我认为您无法在本地实现这一点。但是,您可以尝试禁用分页并手动执行

有一种非常有用的委托方法:

-(void)ScrollViewWillendDraging:(UIScrollView*)scrollView with velocity:(CGPoint)velocity targetContentOffset:(inout CGPoint*)targetContentOffset

让我们来设置scrollView结束滚动的位置

-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
    float offsetY = floorf((*targetContentOffset).y);
    float yGoto = 0.0;

    // Find out, based on that offsetY in which page you are
    // and set yGoto accordingly to the start of that page
    // In the following example my pages are 320px each

    // I start by only allowing to go 1 page at a time, so I limit
    // how far the offsetY can be from the current scrollView offset

    if(offsetY > scrollView.contentOffset.y + 160){
        // Trying to scroll to more than 1 page after
        offsetY = scrollView.contentOffset.y + 160;
    }
    if(offsetY < scrollView.contentOffset.y - 160){
        // Trying to scroll to more than 1 page before
        offsetY = scrollView.contentOffset.y - 160;
    }
    if(offsetY < 0){
        // Trying to scroll to less than the first element
        // This is related to the elastic effect
        offsetY = 0;
    }
    if(offsetY > scrollView.contentSize.height-320){
        // Trying to scroll to more than the last element
        // This is related to the elastic effect
        offsetY = scrollView.contentSize.height - 1;
    }

    // Lock it to offsets that are multiples of 320
    yGoto = floorf(offsetY);
    if((int)offsetY % 320 > 160){
        int dif = ((int)offsetY % 320);
        yGoto = offsetY + 320 - dif;
    }else{
        int dif = ((int)offsetY % 320);
        yGoto = offsetY - dif;
    }

    yGoto = floorf(yGoto); // I keep doing this to take out non integer part
    scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
    (*targetContentOffset) = CGPointMake(scrollView.contentOffset.x,yGoto);
}
-(void)ScrollViewWillendDraging:(UIScrollView*)带速度的scrollView:(CGPoint)速度targetContentOffset:(inout CGPoint*)targetContentOffset{
float offset=floorf((*targetContentOffset).y);
浮动yGoto=0.0;
//根据你所在页面的偏移量找出答案
//并相应地将yGoto设置为该页面的开头
//在下面的示例中,我的每个页面都是320px
//我一开始只允许一次浏览一页,所以我限制
//偏移距当前scrollView偏移的距离
if(offsetY>scrollView.contentOffset.y+160){
//之后尝试滚动到超过1页
offsetY=scrollView.contentOffset.y+160;
}
if(offsetYscrollView.contentSize.height-320){
//尝试滚动到上一个以上的元素
//这与弹性效应有关
offsetY=scrollView.contentSize.height-1;
}
//将其锁定为320的倍数的偏移
yGoto=地板(偏置);
如果((整数)偏移量%320>160){
int-dif=((int)偏移量%320);
yGoto=偏移量+320-dif;
}否则{
int-dif=((int)偏移量%320);
yGoto=偏移-dif;
}
yGoto=floorf(yGoto);//我一直这样做是为了去掉非整数部分
scrollView.decelerationRate=UIScrollViewDecelerationRateFast;
(*targetContentOffset)=CGPointMake(scrollView.contentOffset.x,yGoto);
}
希望有帮助