0

我正在尝试在 上显示图像UIScrollView,所有这些图像都是水平显示的,但是,我在滚动加载图像时遇到了闪烁的问题。

我尝试使用此代码并将 UILabel 修改为 UIImageview 并在滚动时调用异步图像下载scrollViewDidEndDecelerating- Image Scroll Circular,一个只有 3 页。它适用于“文本标签”示例,但是当我异步加载图像(也缓存)时,滚动时会闪烁。

假设,如果我从第 0 页滚动到第 1 页,那么第 0 页会闪烁一会儿,然后可以再次看到第 1 页。

知道如何摆脱这个问题吗?

4

2 回答 2

0

尝试使用当前主队列添加图像:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.scrollView addSubview:imageView];
});
于 2013-01-29T09:50:21.763 回答
0

我的 .m 类您需要一个视图,并在该视图上添加了 imageViewSlider(uiimageview)。将它与活动指示器和分离的图像提取相结合,看看它是否有效。这实现了没有滚动视图的幻灯片

#import "ImageSliderView.h"
#import <QuartzCore/QuartzCore.h>
#define kAnimationKey @"animationKey"
@interface ImageSliderView ()

@end

@implementation ImageSliderView
@synthesize imageData;
@synthesize imageViewSlider;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Set GestureRecoginzer..
    //******************************************************Swipe recognisers**************************
    UISwipeGestureRecognizer *rightRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeHandle:)];

    rightRecognizer.direction=UISwipeGestureRecognizerDirectionRight;

    [rightRecognizer setNumberOfTouchesRequired:1];

    [self.view addGestureRecognizer:rightRecognizer];

    [rightRecognizer release];

    UISwipeGestureRecognizer *leftRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeHandle:)];

    leftRecognizer.direction=UISwipeGestureRecognizerDirectionLeft;

    [leftRecognizer setNumberOfTouchesRequired:1];

    [self.view addGestureRecognizer:leftRecognizer];

    [leftRecognizer release];

    //******************************************************
    currentPage=0;
        // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [self setImageData:nil];
    [self setImageViewSlider:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
-(void)dealloc
{
    [imageData release];
    [imageViewSlider release];
    [super dealloc];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}




#pragma mark ---swipe
-(void)swipeHandle:(UISwipeGestureRecognizer *)guestureRecognizer
{
    if(guestureRecognizer.direction==UISwipeGestureRecognizerDirectionLeft)
    {

         [self nextButtonAndSlideForwad];

    }
    if(guestureRecognizer.direction==UISwipeGestureRecognizerDirectionRight)
    {
                [self prevButtonAndSlideBack];
    }

}



-(void)nextButtonAndSlideForwad
{


    self.imageViewSlider.backgroundColor=[UIColor redColor];
            [self slideForward];



}

-(void)prevButtonAndSlideBack
{
    self.imageViewSlider.backgroundColor=[UIColor greenColor];
    [self slideBackward];
}

-(void)slideForward
{
    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromRight];
    [animation setDuration:0.4f];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; 
    [[self.view layer] addAnimation:animation forKey:kAnimationKey];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.55];
    [UIView commitAnimations];


}

-(void)slideBackward
{

    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromLeft];
    [animation setDuration:0.4f];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0]; 
    [[self.view layer] addAnimation:animation forKey:kAnimationKey];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.55];
    [UIView commitAnimations];

}

@end
于 2013-01-30T07:02:15.473 回答