【问题标题】:fading slideshow in an imageview. xCode 4.2在 imageview 中淡入淡出幻灯片。代码 4.2
【发布时间】:2012-03-15 01:27:05
【问题描述】:

我正在尝试在使用淡入淡出效果的图像视图中制作幻灯片。

到目前为止,我已经这样做了:

    - (void)viewDidLoad
{
    [super viewDidLoad];
    animationView = [[UIImageView alloc] initWithFrame:self.view.frame];
    animationView.animationImages = [NSArray arrayWithObjects:   
                                     [UIImage imageNamed:@"photo1.jpg"],
                                     [UIImage imageNamed:@"photo2.jpg"],
                                     [UIImage imageNamed:@"photo3.jpg"], nil];

    animationView.animationDuration = 5;
    animationView.animationRepeatCount = 0;
    [animationView startAnimating];
    [self.view addSubview:animationView];
}

图像确实会一个接一个地出现,延迟 5 秒,我现在想要的是让它们在每次图像出现时淡入淡出,有什么建议吗?

提前感谢您的帮助

【问题讨论】:

  • 没有人知道答案吗?几天来我一直在努力寻找解决方案,我唯一想到的(这不是很好但有点工作)是通过制作一些空白并用选择器调用它们我设法使图像看起来像淡入并像淡出一样消失(通过更改 alpha),但效果不佳,它给你一种假的褪色感觉

标签: xcode uiimageview xcode4.2 fadein fadeout


【解决方案1】:

我正在尝试做类似的事情。我所做的是在 UIImageView 上设置一个名为 UIView transitionWithView 的计时器,该计时器在我的幻灯片照片数组中递增。

- (void)viewDidLoad{
[super viewDidLoad];
self.welcomePhotos = [NSArray arrayWithObjects:@"welcome_1.png",@"welcome_2.png", @"welcome_3.png", nil];
self.imageView1.image = [UIImage imageNamed:[self.welcomePhotos objectAtIndex:0]];
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(transitionPhotos) userInfo:nil repeats:YES];
}


-(void)transitionPhotos{

if (photoCount < [self.welcomePhotos count] - 1){
    photoCount ++;
}else{
    photoCount = 0;
}
[UIView transitionWithView:self.imageView1
                  duration:2.0
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{ self.imageView1.image = [UIImage imageNamed:[self.welcomePhotos objectAtIndex:photoCount]]; }
                completion:NULL];    
}

【讨论】:

  • 如何在.h 中声明photoCount
  • photoCount 可以在@implementation 下声明为 static int photoCount;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-24
  • 2014-10-10
  • 1970-01-01
  • 2017-12-26
  • 2022-01-25
  • 2011-09-17
相关资源
最近更新 更多