• UIScrollView 用法


    m_Scroll.frame = CGRectMake(0, 0, 320, 480);//重要,设置Srollview控件的位置以及大小属性,

    [m_Scroll setBackgroundColor:[UIColor blackColor]];

    [m_Scroll setCanCancelContentTouches:NO];

    m_Scroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;

    m_Scroll.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview

    m_Scroll.scrollEnabled = YES;

    m_Scroll.pagingEnabled = YES;

    //m_Scroll.contentSize = CGSizeMake(4*320, 480);

    UIView *view_1 =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

    view_1.backgroundColor = [UIColor blueColor];

    UIView *view_2 =[[UIView alloc] initWithFrame:CGRectMake(320, 0, 320, 480)];

    view_2.backgroundColor = [UIColor yellowColor];

    UIView *view_3 =[[UIView alloc] initWithFrame:CGRectMake(2*320, 0, 320, 480)];

    view_3.backgroundColor = [UIColor grayColor];

    UIView *view_4 =[[UIView alloc] initWithFrame:CGRectMake(3*320, 0, 320, 480)];

    view_4.backgroundColor = [UIColor magentaColor];

    [m_Scroll addSubview:view_1];

    [m_Scroll addSubview:view_2];

    [m_Scroll addSubview:view_3];

    [m_Scroll addSubview:view_4];

    [view_1 release];

    [view_2 release];

    [view_3 release];

    [view_4 release];

    /*

    设置UIscrollview内容的大小,

    这里需要注意的是第二个参数[m_Scroll bounds].size.height),这样设置就可以保证,不会在纵向因为子试图过大而滚动

    我们在使用这个控件的时候,尽量设计好,UIScrollview控件的大小,以及起内容的大小,这样就不会出现不必要的滚动。

    */

    [m_Scroll setContentSize:CGSizeMake((320 * 4), [m_Scroll bounds].size.height)];



    2:根据内容的Frame属性,设置可视区域(visible area)

    [scrollView scrollRectToVisible:CGRectMake(index*SceneWidth, 0, SceneWidth, SceneHeight) animated:YES];

    后面的参数是可视区域的Frame属性,我们也可以这样理解,这个方法就是把UIScrollview的视图区域,移动到指定

    Frame的可见区域。

  • 相关阅读:
    【loj2639】[Tjoi2017]不勤劳的图书管理员
    【bzoj3514】Codechef MARCH14 GERALD07加强版
    BZOJ1002【FJOI2007】轮状病毒
    数论基础(附加例题)
    表达式总结
    背包
    hdu1027
    hdu1026
    hdu1025
    hdu1024
  • 原文地址:https://www.cnblogs.com/xingchen/p/2153915.html
Copyright © 2020-2023  润新知