zoukankan      html  css  js  c++  java
  • UIScrollview使用

    改变内容偏移

    - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;  // animate at constant velocity to new offset

    显示contentsize中的某部分

    - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;         // scroll so rect is just visible (nearest edges). nothing if rect completely visible

     

    注意:

    1. 使用 - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated 时, 需要注意, 

    在uiscrollview的委托中只有, 以下这个方法可以阻止减速, 并且更改内容偏移, 一就是setContentOffset这个方法

    - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;  

     

    2. viewForZoomingInScrollView: 需要设置

    minimumZoomScale 

    maximumZoomScale 才能够调用 

    uiscrollview缩放图片至少实现一下两个代理, 但能让缩放过程更加自然

    //实现图片在缩放过程中居中
    //scrollView正在缩放
    - (void)scrollViewDidZoom:(UIScrollView *)scrollView
    {
        CGFloat offsetX = (scrollView.bounds.size.width > scrollView.contentSize.width)?(scrollView.bounds.size.width - scrollView.contentSize.width)/2 : 0.0;
        CGFloat offsetY = (scrollView.bounds.size.height > scrollView.contentSize.height)?(scrollView.bounds.size.height - scrollView.contentSize.height)/2 : 0.0;
        UIView *v = [scrollView.subviews objectAtIndex:0];
        v.center = CGPointMake(scrollView.contentSize.width/2 + offsetX,scrollView.contentSize.height/2 + offsetY);
    }
    
    #pragma mark - UIScrollViewDelegate
    
    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
    {
        return _imageView;
    }
  • 相关阅读:
    Ajax 异步请求返回集合遍历问题
    JS 类数组,字符串,转换成数组的方法
    laravel、TP、YII三个框架的优缺点对比
    纵深防御
    渗透测试小结
    常见的设计模式
    CDN简介
    WAF小介
    分布式事务及其常见的解决方案
    redis主从复制
  • 原文地址:https://www.cnblogs.com/apem/p/4502444.html
Copyright © 2011-2022 走看看