UISCrollView内部放大

//

//  ScrollViewController.m

//  MyScrollView

//

//  Created by lanou on 12-12-20.

//  Copyright (c) 2012年 lanou. All rights reserved.

//

 

#import "ScrollViewController.h"

 

@interfaceScrollViewController ()

 

@end

 

@implementation ScrollViewController

 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    returnself;

}

 

- (void)viewDidLoad

{

    [superviewDidLoad];

    

    _s = [[UIScrollViewalloc]initWithFrame:CGRectMake(0,0,320,480)];

    _s.contentSize = CGSizeMake(320*5,480);

    _s.delegate = self;

    _s.scrollsToTop = YES;//点下title  ScrollView自动滑

    _s.pagingEnabled = YES;//一次滑动一个ScrollView的长或宽

    _s.bounces = NO;//边界可超出单自动缩回

    _s.minimumZoomScale = 2;

    _s.maximumZoomScale = 1;

    [self.viewaddSubview:_s];

    

    for (int i=0; i<5; i++)

    {

        [self addGallery:i];

    }

    //pageControl控件

    _pageControl = [[UIPageControlalloc]initWithFrame:CGRectMake(100, 500, 120, 20)];

    _pageControl.numberOfPages = 4;

    _pageControl.pageIndicatorTintColor = [UIColorredColor];

    _pageControl.currentPageIndicatorTintColor = [UIColorblueColor];

    [_pageControladdTarget:selfaction:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged];

    [self.viewaddSubview:_pageControl];

}

-(void)addGallery:(int)i

{

    UIScrollView *scrollView = [[UIScrollViewalloc]initWithFrame:CGRectMake(320*i, 0, 320, 480)];

    scrollView.minimumZoomScale = 1;

    scrollView.maximumZoomScale = 2;

//    scrollView.contentSize = CGSizeMake(320, 480);

    scrollView.delegate = self;

    UIImageView *imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

    if (i<4)

        {

            NSString *pName = [NSStringstringWithFormat:@"p%d.jpg",i+1];

            imageView.image = [UIImage imageNamed:pName];

        }

    else if(i==4)

        {

            NSMutableArray *images = [NSMutableArrayarrayWithCapacity:1];

            for (int i=1; i<8; i++)

            {

                NSString *name = [NSString stringWithFormat:@"huoju_%d.tiff",i];

                UIImage *image = [UIImage imageNamed:name];

                [images addObject:image];

            }

            imageView.animationImages = images;

            imageView.animationDuration = 1.0;

            [imageView startAnimating];

            [scrollView addSubview:imageView];

        }

    [scrollView addSubview:imageView];

    [_s addSubview:scrollView];

 

    [scrollView release];

    [imageView release];

}

 

-(void)pageChanged:(UIPageControl *)pc

{

    int page = pc.currentPage;

    [_sscrollRectToVisible:CGRectMake(320*page, 50, 320, 350) animated:YES];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    CGFloat pageWidth = scrollView.frame.size.width;

int page = floor((scrollView.contentOffset.x - pageWidth / 2) /pageWidth) +1;

    NSLog(@"%d",page);

_pageControl.currentPage = page;

}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

{

    return [scrollView.subviews objectAtIndex:0];

}

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

@end

 

转载于:https://www.cnblogs.com/debuggle/archive/2012/12/20/2827009.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值