作者

欢迎联系交流

kingmtn@gmail.com

2 Comments

  1. wait121000 说:

    看到你收藏了dota replay parser,其中有一句感言对我有用,我给你发邮件了,我邮箱是wuluo110@163.com

  2. Cynric 说:

    请教一个问题,最近在做一个项目。一个类似电子杂志的项目。因为客户需求,如果用pdf做的话怕影响效率。就把pdf转成分辨率较高的图片,一次读取三个,这样画面上最多就加载三个图片。我使用了UIScrollView的嵌套,一个负责缩放,一个负责翻页。现在的问题是,当负责缩放的View的zoomScale放大的时候,划过屏幕相应的第一个事件是翻页,而不是移动当前的画面。请教如何解决。附上代码://
    // MagazineTestViewController.m
    // MagazineTest
    //
    // Created by Cynric on 10-8-20.
    // Copyright __MyCompanyName__ 2010. All rights reserved.
    //

    #import “MagazineTestViewController.h”
    #import “Manager.h”

    @implementation MagazineTestViewController
    @synthesize scrollView;

    /*
    // The designated initializer. Override to perform setup that is required before the view is loaded.
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
    // Custom initialization
    }
    return self;
    }
    */

    /*
    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView {
    }
    */

    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
    [super viewDidLoad];

    // scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,768,1024)];

    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
    [scrollView setCanCancelContentTouches:NO];
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scrollView.clipsToBounds = YES;
    scrollView.scrollEnabled = YES;
    scrollView.pagingEnabled = YES;

    //[self.view addSubview:scrollView];

    NSUInteger i;

    CGFloat curXLoc = 0;

    for (i = 1; i <= 5; i++)
    {
    // setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
    CGRect frame = CGRectMake(curXLoc, 0, 768, 1000);
    // frame.origin = CGPointMake(curXLoc, 0);
    curXLoc += (768);
    //imageView.tag = i; // tag our images for later use when we place them in serial fashion

    UIScrollView *imgScroller = [[UIScrollView alloc] initWithFrame:frame];

    //UIImage *image = [Manager getImageNoCache:[NSString stringWithFormat:@"002%d.png", i]];

    CGRect rectForImage = CGRectMake(0, 0, 768, 1000);
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:rectForImage];
    imageView.tag = i;
    // [imgScroller]

    // imgScroller.scrollEnabled = YES;
    // imgScroller.pagingEnabled = YES;

    imgScroller.contentSize = CGSizeMake(768, 1000);// rectForImage.size;

    [scrollView addSubview:imgScroller];

    imgScroller.minimumZoomScale = imgScroller.frame.size.width/imageView.frame.size.width;

    imgScroller.maximumZoomScale = 2.0;

    imgScroller.delegate = self;
    imgScroller.tag = 500+i;

    imgScroller.zoomScale = imgScroller.minimumZoomScale;
    NSLog(@"size width: %f",imgScroller.contentSize.width);
    [imgScroller addSubview:imageView];

    [imgScroller release];
    [imageView release];
    }

    scrollView.delegate = self;
    scrollView.tag = 10000;

    UIScrollView *currentScroller = (UIScrollView *)[scrollView viewWithTag:500+1];

    UIImageView *currentView = (UIImageView *)[currentScroller viewWithTag:1];
    currentView.image = [Manager getImageNoCache:[NSString stringWithFormat:@"002%d.png", 1]];

    [scrollView setContentSize:CGSizeMake(5 * 768, 1000)];

    }

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
    }

    - (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
    }

    - (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    }

    #pragma mark delegate method

    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)ascrollView
    {
    if(ascrollView.tag !=10000)
    {
    return ascrollView;
    }
    else {
    return nil;
    }

    }

    - (void)scrollViewWillBeginDragging:(UIScrollView *)ascrollView
    {
    if (ascrollView.tag != 10000) {
    // return ;
    }

    NSInteger currentPage = (NSInteger)(ascrollView.contentOffset.x/768)+1;
    NSLog(@"Begin : currentPage = %d",currentPage);
    if (currentPage = 6) {
    UIScrollView *lastScroller = (UIScrollView *)[ascrollView viewWithTag:500+4];
    UIImageView *lastImageView = (UIImageView *)[lastScroller viewWithTag:4];
    lastImageView.image = [Manager getImageNoCache:[NSString stringWithFormat:@"002%d.png", 4]];

    } else {
    UIScrollView *lastScroller = (UIScrollView *)[ascrollView viewWithTag:500+currentPage-1];
    UIImageView *lastImageView = (UIImageView *)[lastScroller viewWithTag:currentPage-1];
    NSString *tmpStr = [NSString stringWithFormat:@"002%d.png",currentPage-1];
    // lastImageView.image = [Manager getImageNoCache:[NSString stringWithFormat:@"%@", tmpStr]];
    lastImageView.image = [UIImage imageNamed:tmpStr];

    UIScrollView *nextScroller = (UIScrollView *)[ascrollView viewWithTag:500+currentPage+1];
    UIImageView *nextImageView = (UIImageView *)[nextScroller viewWithTag:currentPage+1];
    NSString *tmpStr1 = [NSString stringWithFormat:@"002%d.png",currentPage+1];
    // nextImageView.image = [Manager getImageNoCache:[NSString stringWithFormat:@"%@", tmpStr1]];
    nextImageView.image = [UIImage imageNamed:tmpStr1];

    }
    }

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)ascrollView
    {
    NSInteger currentPage = (NSInteger)(ascrollView.contentOffset.x/768)+1;
    NSLog(@”End : currentPage = %d”,currentPage);
    for (NSInteger i = 1; i <= 5; i++) {
    if (i != currentPage) {
    UIScrollView *currentScroller = (UIScrollView *)[ascrollView viewWithTag:500+i];

    UIImageView *otherImageView = (UIImageView *)[currentScroller viewWithTag:i];
    otherImageView.image = nil;
    }
    }
    UIScrollView *currentScrollerView = (UIScrollView *)[ascrollView viewWithTag:500+currentPage];

    UIImageView *currentView = (UIImageView *)[currentScrollerView viewWithTag:currentPage];
    if (currentView.image == nil) {
    // NSString *tmpStr = [NSString stringWithFormat:@"fxjyogapic%d.png",currentPage+1];
    currentView.image = [Manager getImageNoCache:[NSString stringWithFormat:@"002%d.png", currentPage]];
    //currentView.image = [UIImage imageNamed:[NSString stringWithFormat:@"fxjofficeExciresebg%d.png",currentPage+1]];
    }
    }

    - (void)scrollViewDidScrollToTop:(UIScrollView *)ascrollView
    {
    NSLog(@"Scrolling tag:%d",ascrollView.tag);
    }

    - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
    {

    }

    - (void)dealloc {
    [super dealloc];
    }

    @end

Leave a Reply