Custom transition between two UIViews

后端 未结 6 602
暗喜
暗喜 2020-12-17 01:55

I have two views \"A\" and \"B\". A floats in the middle of the window (it\'s not full screen). B, the view which will replace A, is full screen. I\'d like to write a custom

6条回答
  •  天涯浪人
    2020-12-17 02:48

    This is an easy example that i made for you :-) Start with it... Try to understand it... Read Documentation and then you will be able to do what you want ;-)

    - (void)moveTable:(UITableView *)table toPoint:(CGPoint)point excursion:(CGFloat)excursion {
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.5];
    [table setCenter:point];
    
    // scaling
    CABasicAnimation *scalingAnimation = (CABasicAnimation *)[table.layer animationForKey:@"scaling"];
    if (!scalingAnimation)
    {
        scalingAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
        scalingAnimation.duration=0.5/2.0f;
        scalingAnimation.autoreverses=YES;
        scalingAnimation.removedOnCompletion = YES;
        scalingAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        scalingAnimation.fromValue=[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(0.0, 0.0, 0.0)];
        scalingAnimation.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(excursion, 0.0, 0.0)];
    }
    [table.layer addAnimation:scalingAnimation forKey:@"scaling"];
    [UIView commitAnimations];
    

    }

提交回复
热议问题