suchen

Heim  >  Fragen und Antworten  >  Hauptteil

So bleibt die Position in iOS unverändert, aber nur die Breite ändert sich.

    CABasicAnimation *leftboundsanimation = [CABasicAnimation animationWithKeyPath:@"bounds.size.width"];
    leftboundsanimation.fromValue = [NSNumber numberWithFloat:1];
    //[NSValue valueWithCGSize:CGSizeMake(1, 20)];
    leftboundsanimation.toValue   = [NSNumber numberWithFloat:animationrectwidth/2-0.5];

// [NSValue valueWithCGSize:CGSizeMake(animationrectwidth/2-0.5, 20)];

    leftboundsanimation.removedOnCompletion  =   NO;
    leftboundsanimation.fillMode =   kCAFillModeForwards;
    leftboundsanimation.duration  = 1.3;
    leftboundsanimation.beginTime   =   2.7;
过去多啦不再A梦过去多啦不再A梦2742 Tage vor721

Antworte allen(1)Ich werde antworten

  • PHPz

    PHPz2017-05-17 10:07:26

    CABasicAnimation version:

    How to change the width of a CALayer with animation from left to right?

    CGRect bounds = self.view.bounds;
    CALayer *layer = self.view.layer;
    layer.position = CGPointMake(0, 0);
    layer.anchorPoint = CGPointMake(0, 0);
    
    CABasicAnimation *leftBoundsAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];
    leftBoundsAnimation.duration = 1.3;
    leftBoundsAnimation.toValue = [NSValue valueWithCGRect:bounds];
    bounds.size.width = 0;
    leftBoundsAnimation.fromValue = [NSValue valueWithCGRect:bounds];
    
    [layer addAnimation:leftBoundsAnimation forKey:@"leftBoundsAnimation"];

    UIView其实有直接提供动画方法的。
    改变一个view的宽度:

    CGRect frame = self.view.frame;
    frame.size.width = 300;
    [UIView animateWithDuration:1.3 animations:^{
        self.view.frame = frame;
    }];

    Antwort
    0
  • StornierenAntwort