当前位置:编程学习 > wap >>

按钮滑动的动画效果

我现在想实现这样的效果,一个按钮平滑地从一个位置滑动到另一个位置,请问这个可以通过动画效果实现吗?具体要怎么做呢,谢谢! --------------------编程问答--------------------

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0); // delay = 0.0, options = 0

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0); // delay = 0.0, options = 0, completion = NULL

这三个动画函数即可。把按钮的frame改变一下。 --------------------编程问答--------------------
引用 1 楼  的回复:
C/C++ code

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL f……
谢谢 我试试看 --------------------编程问答-------------------- 我使用了如下代码,实现每次点击背景,按钮平滑移动,但是只有第一次点击的时候按钮是平滑地移动。
- (void)move
{
    __block CGRect rect = button.frame;
    
    [UIView animateWithDuration:0.5
                     animations:^{
                         //button.transform = CGAffineTransformMakeRotation(3.14);
                         button.transform = CGAffineTransformMakeTranslation(20, 20);
                     }
                     completion:^(BOOL finished){
                         rect.origin.x+=20;
                         rect.origin.y+=20;
                         button.frame = rect;
                     }];
}
- (IBAction)bkTap:(id)sender
{
    [self move];
}
--------------------编程问答-------------------- 可能第一次移动后状态改变了,你需要重置状态。 --------------------编程问答--------------------
引用 4 楼  的回复:
可能第一次移动后状态改变了,你需要重置状态。
已解决 谢谢 --------------------编程问答-------------------- 留个资料 方便以后用 --------------------编程问答--------------------
引用 6 楼  的回复:
留个资料 方便以后用
fOffsetX,fOffsetY表示移动的话,代码这么写就对了:
fOffsetX+=20;
fOffsetY+=20;
CGAffineTransformMakeTranslation(fOffsetX, fOffsetY); --------------------编程问答-------------------- mark,我知道我以后会用上! --------------------编程问答--------------------  必须记住,mark --------------------编程问答-------------------- soga。。受教了! --------------------编程问答-------------------- 不错,学习下。 --------------------编程问答-------------------- 楼主,已经解决了就要结贴啊
补充:移动开发 ,  iPhone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,