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;
    }
  • 相关阅读:
    LeetCode59 Spiral Matrix II
    LeetCode58 Length of Last Word
    LeetCode54 Spiral Matrix
    LeetCode63 Unique Paths II
    LeetCode62 Unique Paths
    LeetCode55 Jump Game
    网易2017年校招笔试题 最大的奇约数
    Codeforces Round #119 (Div. 2)
    Codeforces Round #118 (Div. 2)
    2016 MIPT Pre-Finals Workshop Taiwan NTU Contest
  • 原文地址:https://www.cnblogs.com/apem/p/4502444.html
Copyright © 2011-2022 走看看