Iphone 设置UIView过渡的动画,如“展开点到圆”

Iphone 设置UIView过渡的动画,如“展开点到圆”,iphone,ios,objective-c,uiview,uiviewanimationtransition,Iphone,Ios,Objective C,Uiview,Uiviewanimationtransition,在我的iPhone应用程序中,我需要实现不同类型的转换 那是 从当前视图打开的下一个视图 它像一个点一样进行统计,点像一个圆一样缓慢地展开,下一个视图将部分显示在圆的一部分中,最后圆将完全展开,下一个视图将完全显示 我在cocoa controller上搜索了很多过渡,比如CATTransitions和一些动画,但我没有找到这种类型的过渡,有人能帮我吗 我想我可以给你一个解决办法。而不是像点一样推到下一个视图。我建议您在视图的视图中添加一个简单的点动画,该视图将出现在您必须被推入的视图中。现在,

在我的iPhone应用程序中,我需要实现不同类型的转换

那是

从当前视图打开的下一个视图

它像一个点一样进行统计,点像一个圆一样缓慢地展开,下一个视图将部分显示在圆的一部分中,最后圆将完全展开,下一个视图将完全显示

我在cocoa controller上搜索了很多过渡,比如CATTransitions和一些动画,但我没有找到这种类型的过渡,有人能帮我吗


我想我可以给你一个解决办法。而不是像点一样推到下一个视图。我建议您在视图的
视图中添加一个简单的点动画,该视图将出现在您必须被推入的视图中。现在,push方法将保持不变

[self.navigationController pushViewController:NewView animated:YES];

但是在
视图中将出现
该代码将使点扩展为一个圆,并显示其下方的新视图。希望你理解我在这里解释的逻辑。任何问题都要让我知道。

就我而言,我是这样做的:

CAShapeLayer
实例设置为自定义视图子类的图层掩码属性

@interface MyCustomView ()
@property (nonatomic, strong) CircleShapeLayer *circleShapeLayer;
@end

@implementation MyCustomView

- (id) initWithFrame: (CGRect) frame {
    self = [super initWithFrame: CGRectZero];
    if (self) {
        self.layer.mask = self.shapeLayer;
        [self.layer.mask setValue: @(0) forKeyPath: @"transform.scale"];
    }
    return self;
}
将此遮罩层缩放为全尺寸。您的视图代码:

- (void) zoom {
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath: @"transform.scale"];
    animation.fromValue = [self.layer.mask valueForKeyPath: @"transform.scale"];
    animation.toValue = @(1);
    animation.duration = 2.0;
    animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
    animation.delegate = self;
    // Important: change the actual layer property before installing the animation.
    [self.layer.mask setValue: animation.toValue forKeyPath: animation.keyPath];
    // Now install the explicit animation, overriding the implicit animation.
    [self.layer.mask addAnimation: animation forKey: animation.keyPath];
    return;
}

- (CAShapeLayer *) circleShapeLayer {
    if (!_ circleShapeLayer) {
        _circleShapeLayer = [SGMaskLayer layer];
        _circleShapeLayer.delegate = _shapeLayer;
        _circleShapeLayer.frame = self.bounds;
        _circleShapeLayer.needsDisplayOnBoundsChange = YES;
    }

    return _circleShapeLayer;
}

@end
遮罩层的代码:

@interface CircleShapeLayer : CAShapeLayer
@end

@implementation CircleShapeLayer

- (void) drawLayer: (CALayer *) layer inContext: (CGContextRef) ctx {
    UIGraphicsPushContext(ctx);
    UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect: self.bounds];
    self.path = circlePath.CGPath;
    UIGraphicsPopContext();
}

@end
从文件中:

层的alpha通道确定层内容的多少 和背景显示通过。完全或部分不透明像素允许 要通过完全透明的像素显示的底层内容 阻止该内容

此属性的默认值为nil nil。在配置 蒙版时,请记住将蒙版层的大小和位置设置为 确保它与它遮罩的层正确对齐

所以我用UIBezierPath画了一个圆来实现圆形遮罩。在开始时,我将遮罩的比例因子设置为0,以便视图的图层不可见。然后将“比例因子”(scale factor)设置为1(填充层的边界)动画,这将生成一个圆的动画,该圆的半径从中心开始逐渐增大


您可能还需要一个动画来移动视图的中心点。两个动画都可以包装在一个动画组中。

在第一视图中打开:

//未选择批注的委托方法 -(void)TapolAnnotation:(RMANotation*)地图上的注释:(RMMapView*)地图; { //获取GMS标记的接触点,将其设置为圆形过渡位置 CGPoint-markerPoint=annotation.position; x=标记点.x; y=标记点y

    circleSize = 10;
    radiusChange = 0;

    //Populate Same Values to next view to close
    VenueScreen.x = x;
    VenueScreen.y = y;

    VenueScreen.view.hidden = YES;
    timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(openVenueScreen) userInfo:nil repeats:YES];
    VenueScreen.view.frame = CGRectMake(0, 0, 320, 480);
    [self.view addSubview:VenueScreen.view];

}



//Circular transition to open Next view
-(void)openVenueScreen
{
    VenueScreen.view.hidden = NO;
    VenueScreen.view.userInteractionEnabled = NO;
    VenueScreen.view.alpha = 0.9;
    self.view.userInteractionEnabled = NO;

    int rChange = 0; // Its doing proper masking while changing this value
    int radius = circleSize-rChange;

    CAShapeLayer *circleShapeLayer = [CAShapeLayer layer];

    // Make a circular shape
    circleShapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(x+radiusChange, y+radiusChange, 2.0*radius, 2.0*radius)
                                                       cornerRadius:radius].CGPath;
    radiusChange = radiusChange-10;

    // Configure the apperence of the circle
    [[VenueScreen.view layer] setMask:circleShapeLayer];

    //Start Transition
    circleSize = circleSize+10;

    if (circleSize > 480)
    {
        [[VenueScreen.view layer] setMask:nil];

        [timer invalidate]; //Stop titmer

        VenueScreen.view.userInteractionEnabled = YES;
        self.view.userInteractionEnabled = YES;
        VenueScreen.view.alpha = 1;

        //Populate to next view to close
        VenueScreen.radiusChange = radiusChange;
    }

}
在下一个视图中关闭:

//关闭按钮动作
-(iAction)DismissVenueScreen:(id)发送方;
{
计时器=[NSTimer scheduledTimerWithTimeInterval:0.01目标:自选择器:@selector(dismissVenueScreen)用户信息:无重复:是];
NSLog(“关闭按钮关闭”);
}
//关闭窗口的圆形平移
-(无效)解除安全屏幕
{
int rChange=0;//它在更改此值时执行正确的掩蔽
int radius=圆圈大小的rChange;
CAShapeLayer*circleShapeLayer=[CAShapeLayer层];
//做成圆形
circleShapeLayer.path=[UIBezierPath bezierPathWithRoundedRect:CGRectMake(x+半径变化,y+半径变化,2.0*半径,2.0*半径)
拐角半径:半径].CGPath;
//配置圆的外观
[[self.view layer]设置掩码:circleShapeLayer];
self.view.layer.masksToBounds=是;
半径变化=半径变化+10;
circleSize=circleSize-10;

如果有什么方法可以绕过动画,我想可能会有帮助,但要清楚一些please@hacker2007你能告诉我更多关于“myView”、“self.shapeLayer”和“self.layer”的细节吗?
//Close button Action
-(IBAction)DismissVenueScreen:(id)sender;
{
    timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(dismissVenueScreen) userInfo:nil repeats:YES];
    NSLog(@"close button clciked");
}

//Circular trasition to Close window
-(void)dismissVenueScreen
{
    int rChange = 0; // Its doing proper masking while changing this value
    int radius = circleSize-rChange;

    CAShapeLayer *circleShapeLayer = [CAShapeLayer layer];
    // Make a circular shape
    circleShapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(x+radiusChange,y+radiusChange, 2.0*radius, 2.0*radius)
                                                       cornerRadius:radius].CGPath;

    // Configure the apperence of the circle
    [[self.view layer] setMask:circleShapeLayer];
    self.view.layer.masksToBounds = YES;

    radiusChange = radiusChange+10;
    circleSize = circleSize-10;

    if (circleSize <= 0)
    {
        [timer invalidate]; //Stop titmer
        [[self.view layer] setMask:nil];
        [self.view removeFromSuperview];
        circleSize = 480;
    }

}