Images faden

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Images faden

    Schönen Abend Euch!
    Ich tue mich gerade mit ein paar Images schwer, welche einen weichen Übergang haben sollen.

    Quellcode

    1. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, (self.view.frame.size.width)*2/3)];
    2. imgView.animationImages=[NSArray arrayWithObjects:
    3. [UIImage imageNamed:@"scroll1.png"],
    4. [UIImage imageNamed:@"scroll2.png"],
    5. [UIImage imageNamed:@"scroll3.png"],
    6. [UIImage imageNamed:@"scroll4.png"],
    7. [UIImage imageNamed:@"scroll5.png"],
    8. [UIImage imageNamed:@"scroll6.png"], nil];
    9. imgView.animationDuration=20.0;
    10. imgView.animationRepeatCount=0;
    11. CATransition *transition = [CATransition animation];
    12. transition.type = kCATransitionFade;
    13. transition.duration = 0.34;
    14. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    15. [imgView.layer addAnimation:transition forKey:nil];
    16. [imgView startAnimating];
    17. [self.view addSubview:imgView];
    Alles anzeigen
    Was mache ich falsch?

    LG
    Bernd
    Ich bin gegen Signaturen!!!
  • Du startest die Animation bevor du den View in die View Hierarchie einfügst.
    Aber kannst du nicht einfach die Property alpha vom UIImageView animieren?

    Quellcode

    1. __typeof__(self) __weak weakSelf = self;
    2. [UIView animateWithDuration:kAnimationDuration animations:^{
    3. [weakSelf.imgView.alpha = <neuer Wert>;
    4. }];
  • Michael schrieb:


    Quellcode

    1. __typeof__(self) __weak weakSelf = self;
    2. [UIView animateWithDuration:kAnimationDuration animations:^{
    3. [weakSelf.imgView.alpha = <neuer Wert>;
    4. }];
    Warum der Umstand mit weakSelf? Weder ist imgView eine Property noch sollte der Retain-Zyklus schlimm sein, schließlich gibt iOS den Block während der Ausführung von animatedWithDuration:animations: frei.
    „Meine Komplikation hatte eine Komplikation.“
  • Ich mache es jetzt so:

    Quellcode

    1. - (void)viewDidLoad
    2. {
    3. [super viewDidLoad];
    4. ...
    5. imgViewa = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, (self.view.frame.size.width)*2/3)];
    6. [self.view addSubview:imgViewa];
    7. [imgViewa setAlpha:1.0];
    8. imgViewb = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, (self.view.frame.size.width)*2/3)];
    9. [self.view addSubview:imgViewb];
    10. [imgViewb setAlpha:0.0];
    11. imageArray = [NSArray arrayWithObjects:
    12. [UIImage imageNamed:@"scroll0.png"],
    13. [UIImage imageNamed:@"scroll1.png"],
    14. [UIImage imageNamed:@"scroll2.png"],
    15. [UIImage imageNamed:@"scroll3.png"],
    16. [UIImage imageNamed:@"scroll4.png"],
    17. [UIImage imageNamed:@"scroll5.png"],
    18. [UIImage imageNamed:@"scroll6.png"], nil];
    19. aIndex = 0, bIndex = 1;
    20. [imgViewa setImage:[imageArray objectAtIndex:aIndex]];
    21. NSTimer *timer = [NSTimer timerWithTimeInterval:5.0
    22. target:self
    23. selector:@selector(onTimer)
    24. userInfo:nil
    25. repeats:YES];
    26. [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
    27. [timer fire];
    28. ...
    29. }
    30. -(void)onTimer{
    31. [UIView animateWithDuration:3 animations:^{
    32. //set the image of the image that is not currently visible
    33. if (imgViewa.alpha == 0) {
    34. [imgViewa setImage:[imageArray objectAtIndex:aIndex]];
    35. }
    36. if (imgViewb.alpha == 0) {
    37. [imgViewb setImage:[imageArray objectAtIndex:bIndex]];
    38. }
    39. //make sure the images rotate
    40. [imgViewa setAlpha:imgViewa.alpha == 0 ? 1 : 0];
    41. [imgViewb setAlpha:imgViewb.alpha == 0 ? 1 : 0];
    42. //make sure the images play in a loop
    43. aIndex = aIndex < [imageArray count]-1 ? bIndex+1 : 0;
    44. bIndex = bIndex < [imageArray count]-1 ? bIndex+1 : 0;
    45. }];
    46. }
    Alles anzeigen
    Ich bin gegen Signaturen!!!