判断ScrollView的上下滚动 动态改变view的大小

当tableview滚动时,动态计算view的高度,代码:

//背景view
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    contentOffsetY = scrollView.contentOffset.y;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    newContentOffsetY = scrollView.contentOffset.y;
    if (newContentOffsetY > oldContentOffsetY && oldContentOffsetY > contentOffsetY) {
        // 向上滚动
        [self scrollToTop:scrollView];
    } else if (newContentOffsetY < oldContentOffsetY && oldContentOffsetY < contentOffsetY) {
        // 向下滚动
         [self scrollToBottom:scrollView];
    }//如果不做这步判断,快速拖动时,会出现闪一下的bug
    if (scrollView.dragging) {
        if ((scrollView.contentOffset.y - contentOffsetY) > 0.f) {
            [self scrollToTop:scrollView];
        } else if ((contentOffsetY - scrollView.contentOffset.y) > 0.f) {
            [self scrollToBottom:scrollView];
        }
    }
}

- (void)scrollToBottom:(UIScrollView *)scrollView {
    // 向下滚动
    CGRect rect = self.bgView.frame;
    rect.size.height = (- scrollView.contentOffset.y);
    rect.origin.y = TOP_HEIGHT;
    self.bgView.frame = rect;
}

- (void)scrollToTop:(UIScrollView *)scrollView {
    // 向上滚动
    CGRect rect = self.bgView.frame;
    rect.size.height = (- scrollView.contentOffset.y);
    rect.origin.y = TOP_HEIGHT;
    self.bgView.frame = rect;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {

    oldContentOffsetY = scrollView.contentOffset.y;
}
时间: 2024-08-15 05:25:17

判断ScrollView的上下滚动 动态改变view的大小的相关文章

Android 代码动态改变View的属性

原创文章,转载请注明 http://blog.csdn.net/leejizhou/article/details/51150116 李济洲的博客 设置Android View的长宽和位置我们平时都会在Layout的XML中定义,那么什么时候需要动态在代码中设置View的属性呢?先看下面这个UI设计 在这个UI设计中,上面的ImageView被设计成是长宽是16:9的比例,因为手机屏幕的区别,图片的宽度是无法确定的,所以在XML中是无法设置16:9比例的ImageView,因此想要实现这个UI效

分享非常有用的Java程序 (关键代码)(四)---动态改变数组的大小

原文:分享非常有用的Java程序 (关键代码)(四)---动态改变数组的大小 /** * Reallocates an array with a new size, and copies the contents * * of the old array to the new array. * * @param oldArray the old array, to be reallocated. * * @param newSize the new array size. * * @return

Android 动态改变Layout的大小

设置View的大小是通过设置LayoutParams参数. 如果一个view在一个RelativeLayout里面,需要用一个RelativeLayout.LayoutParams对象来设置 在代码里面设置的高度height是px,如果想用dp单位设置,需要获取屏幕的密度,然后转换. final float scale = getActivity().getResources().getDisplayMetrics().density; int height = (int) (48 * scal

Android 自定义SeekBar动态改变 硬件音量大小 实现和音量键的同步

1,上图: 2,代码: MainActivity.java package com.hero.zhaoq.seekbarchangeddemo; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.database.ContentObse

用javascript动态改变网页文字大小

<script>function setFontSize(size){document.getElementById('bottom').style.fontsize=size+'pt';}</script> 以上代码执行不了,找了半天才发现原来是fontSize出了问题,太马虎了....= =,一定要注意呀,不要写成fontsize,记住这个教训,一定要注意大小写问题!!! 应改为 <script>function setFontSize(size){document

动态改变dialog对话框大小

//在dialog.show()之后调用 public static void setDialogWindowAttr(Dialog dlg,Context ctx){     Window window = dlg.getWindow();     WindowManager.LayoutParams lp = window.getAttributes();     lp.gravity = Gravity.CENTER;     lp.width = LayoutParams.WRAP_CO

img超出div width时, jQuery动态改变图片显示大小

参考: 1. http://blog.csdn.net/roman_yu/article/details/6641911 2. http://www.cnblogs.com/zyzlywq/archive/2012/02/23/2364292.html

jQuery动态改变图片显示大小(修改版)

$(document).ready(function() { $('.post img').each(function() { var maxWidth = 100; // 图片最大宽度 var maxHeight = 100; // 图片最大高度 var ratio = 0; // 缩放比例 var width = $(this).width(); // 图片实际宽度 var height = $(this).height(); // 图片实际高度 // 检查图片是否超宽 if(width >

IOS 判断scrollView是否滑动到底部

判断scrollView有没有滚动到视图的底部,用来做些什么事情.也可以用来实现qq空间的好友动态哪个下拉之后,顶部图片随着拉伸的效果 - (void)scrollViewDidScroll:(UIScrollView *)scrollView1 { CGPoint offset = scrollView1.contentOffset; CGRect bounds = scrollView1.bounds; CGSize size = scrollView1.contentSize; UIEdg