相关疑难解决方法(0)

如何在不添加/删除地图的情况下移动MKAnnotation?

是否可以移动MKAnnotation的坐标而无需在地图中添加和删除注释?

iphone objective-c mapkit mkmapview

36
推荐指数
4
解决办法
2万
查看次数

在完成之前取消UIView animateWithDuration

我在我的项目中有这个代码:

- (void) fadeImageView {
    [UIView animateWithDuration:1.0f
                          delay:0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{
                         self.imageView.alpha = 0.0f;
                     }
                     completion:^(BOOL finished) {
                         //make the image view un-tappable.
                         //if the fade was canceled, set the alpha to 1.0
                     }];

}
Run Code Online (Sandbox Code Playgroud)

但是,有时我想在imageview变得不可见之前取消此操作.有没有办法取消动画中期动画?

uiview uianimation ios quartz-core

18
推荐指数
3
解决办法
1万
查看次数

iOS在完成之前停止animateWithDuration

我有一个CollectionView,我想在用户选择的CollectionViewCell中创建一个动画.我选择使用animateKeyframesWithDuration,因为我想逐步创建自定义动画.我的代码看起来像这样:

func animate() {
    UIView.animateKeyframesWithDuration(1.0, delay: 0.0, options: .AllowUserInteraction, animations: { () -> Void in
        UIView.addKeyframeWithRelativeStartTime(0.0, relativeDuration: 0.5, animations: { () -> Void in
            //  First step
        })
        UIView.addKeyframeWithRelativeStartTime(0.5, relativeDuration: 0.5, animations: { () -> Void in
            //  Second step
        })
        }) { (finished: Bool) -> Void in
            if self.shouldStopAnimating {
                self.loadingView.layer.removeAllAnimations()
            } else {
                self.animate()
            }
        }
}
Run Code Online (Sandbox Code Playgroud)

选中此选项后,将在自定义CollectionViewCell内执行此操作.问题是我想强制在某个时刻立即停止动画.但是当我这样做时,动画并没有完全停止,它只是将剩下的动画移动到另一个单元格(可能是最后一个重用的单元格?)

我不明白为什么会这样.我尝试了不同的方法,但在正常进入完成块之前,它们都没有成功停止动画

有没有人对此有任何想法?

ios animatewithduration swift ios-animations

5
推荐指数
1
解决办法
1192
查看次数

更改正在进行的动画

基本上,我想要做的是为云动画,然后在风变化时改变动画中的速度和/或方向.如果重要的是,我从UIViewController控制整个事情,云存在一个UIView,其上面有一个CALayer,这就是云本身.我也尝试过UIImageView.

对于TL:DR类型,简而言之,我要做的是获取动画视图的位置,或使用块动画停止动画视图.

这是完整的故事.我的问题是在动画期间获得它的位置.我正在使用块动画.因为我只知道它应该移动的速度,我需要通过使用距离来计算自己的时间.我尝试了以下代码,以及它的几个变体:

[[Cloud CloudImage]convertPoint:CGPointMake([[[Cloud CloudImage] presentationLayer] position].x, 0) toLayer:self.layer].x
Run Code Online (Sandbox Code Playgroud)

Cloud是UIView,CloudImage是CALayer.这是我尝试过的最复杂的变化,我尝试了各种更简单的变体(例如,直接询问云,或者使用UIView而不是CALayer).但是,它返回的只是它的最终值.我读了一些关于这个方法从3.2中被破坏的东西,但在4.2中被修复了; 但是,当我将部署目标更改为iOS 4.3而不是4.0时,它没有修复.我正在使用4.3 base sdk.

我考虑的一些其他变化是暂时停止动画片刻,然后立即获得位置并开始新动画.但是,我需要知道一种在其轨道中停止基于块的动画的方法,并且我只找到了旧动画系统的片段(commitanimations).

我考虑的最后一个是编写自己的动画系统; 云将在0.08秒左右重复NSTimer,并在每次触发时创建0.08秒的核心动画,为此它使用给予云的速度作为属性.但是,我担心这种情况的任何变化都会有更低的性能,而我需要它尽可能轻,因为我同时有多达20个这样的云(有时也有雨).

提前致谢!

iphone xcode core-animation objective-c ios

4
推荐指数
1
解决办法
2067
查看次数

如何在iPhone-OS中终止正在运行的动画?

我有一个类"Cube",并且有一个方法-rotate.该方法将anchorPoint设置在左下角,然后将立方体旋转90度.之后,调用另一种方法,使立方体向后旋转-90度.这已经完成了指定停止选择器.顺便说一下:这没什么特别的.刚刚学习!

-rotate在触摸事件时被调用.但是现在,当立方体对象仍在旋转时,假设它当前处于33.943 ......,用户可能会在该动画结束之前再次触摸事件.

然后,该触摸事件将立即再次调用-rotate方法.会发生的是,转换重叠并且立方体图像完全伸展和变形.

因此,在新动画开始之前,当前正在运行的动画必须停止.

UPDATE

在我开始动画之前,我称之为:

- (void)resetAnimation {
    self.layer.transform = CATransform3DIdentity; // reset the transform to the identity transform ("no rotation applied, please")
    [Cube setAnimationDelegate:nil];
    [Cube setAnimationDidStopSelector:NULL];
}
Run Code Online (Sandbox Code Playgroud)

另外,我设置了[Cube setAnimationBeginsFromCurrentState:YES]; 我开始动画块的地方.

因此,当动画从外部进入时,它将如下所示:(注意,屏幕上有5个此类的对象,可以踢到动画)

- (void)kickAnimation { // if that's called, the cube gets a kick to rotate
    self.layer.transform = CATransform3DIdentity;
    currentDegrees = 90; // just testing! it may also be negative
    NSString *animID = [NSString stringWithFormat:@"cube_%i",self.datasetID];
    if (currentDegrees > 0) {
        [self rotateRight:animID finished:0 context:self];
    } else if (currentDegrees …
Run Code Online (Sandbox Code Playgroud)

iphone core-animation

3
推荐指数
1
解决办法
2615
查看次数

取消UIView动画

我使用下面的代码进行摇动按钮如何在正在进行时取消它?

#define RADIANS(degrees) ((degrees * M_PI) / 180.0)

    CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-10.0));
    CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(10.0));

    btn.transform = leftWobble;  // starting point

    [UIView beginAnimations:@"wobble" context:btn];
    [UIView setAnimationRepeatAutoreverses:YES]; // important
    [UIView setAnimationRepeatCount:20];
    [UIView setAnimationDuration:0.1];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(wobbleEnded:finished:context:)];

    btn.transform = rightWobble; // end here & auto-reverse
    [UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)

ios

3
推荐指数
1
解决办法
4547
查看次数

停止UIView动画

可能重复:
取消UIView动画?

我有以下动画,我想按下按钮时停止它.你能告诉我我该怎么办?我无法弄清楚如何.谢谢.

-(void)animationLoop:(NSString *)animationID finished:(NSNumber *)finished context:(void    *)context 
{
[UIView beginAnimations:@"Move randomly" context:nil]; 
[UIView setAnimationDuration:1]; 
// [UIView setAnimationBeginsFromCurrentState:NO];


CGFloat x = (CGFloat) (arc4random() % (int) self.bounds.size.width); 
CGFloat y = (CGFloat) (arc4random() % (int) self.bounds.size.height); 

CGPoint squarePostion = CGPointMake(x, y); 
strechView.center = squarePostion; 

[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationLoop:finished:context:)];

[UIView commitAnimations];

} 
Run Code Online (Sandbox Code Playgroud)

xcode objective-c uibutton uiviewanimation ios

3
推荐指数
1
解决办法
1万
查看次数

如何中断UIView动画

我已经尝试过关于其他几个线程的建议,但他们的方法在这种情况下似乎不起作用.这是我的情况:

我有2个滚动视图."滚动视图A"具有在滚动"滚动视图A"时淡入和淡出的标签.拖动"滚动视图B"时,我想立即隐藏"滚动视图A"上的标签.但是我不能打断标签的慢速淡出动画.以下是我使用的两种方法:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{

if (scrollView.tag != 1)
{
    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState animations:^{

        self.liveOverlayLabel.alpha = .6;
    } completion:^(BOOL finished) {
    }];
}

else
{

    [UIView animateWithDuration:0 delay:0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState animations:^{

        self.liveOverlayLabel.alpha = 0;
    } completion:^(BOOL finished) {
        self.liveOverlayLabel.alpha = 0;
    }];
}
}

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{

if (scrollView.tag != 1)
{

        NSLog(@"stoppping");
    [UIView animateWithDuration:5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{

        self.liveOverlayLabel.alpha = 0;
    } completion:^(BOOL finished) {
    }];
}
else
{
    self.liveOverlayLabel.alpha = 0;

}

}
Run Code Online (Sandbox Code Playgroud)

objective-c uiview ios

2
推荐指数
1
解决办法
1501
查看次数