Latest 1.0
Homepage https://github.com/Insfgg99x/USAction
License MIT
Platforms ios 6.0, requires ARC
Frameworks Foundation, UIKit
Authors

类似SpriteKit的SKAction,你可以在UIKit上使用USAction,用法同SpriteKit的SKAction

USAction

使用

run

+ (instancetype)run:(void(^)(void))handler;
USAction *action = [USAction run:^{
    //do something
}];

move

+ (instancetype)moveTo:(CGPoint)point duration:(NSTimeInterval)interval;
USAction *move = [USAction moveTo:CGPointZero duration:0.5];

wait

+ (instancetype)wait:(NSTimeInterval)interval;
USAction *wait = [USAction wait:0.2];

sequence

+ (instancetype)sequence:(NSArray<USAction *> *)actions;
 USAction *sequence = [USAction sequence:@[action1, action2, action3]];

repeat

+ (instancetype)repeat:(USAction *)action count:(NSInteger)count;
USAction *repeat = [USAction repeat:sequence count:25];

repeatForEver

+ (instancetype)repeatForEver:(USAction *)action;
USAction *repeat = [USAction repeatForEver:sequence];

嵌套示例

- (void)viewDidLoad {
    [super viewDidLoad];

    USAction *add = [USAction run:^{
        [self addNewNode];
    }];
    USAction *wait = [USAction wait:0.2];
    USAction *sequence = [USAction sequence:@[add, wait]];
    USAction *repeat = [USAction repeatForEver:sequence];
    [self.view run:repeat];
}
- (void)addNewNode {
    UIView *node = [self dropNode];
    [self.view addSubview:node];
    USAction *move = [USAction moveTo:CGPointMake(arc4random_uniform((int)self.view.bounds.size.width) + 1, self.view.bounds.size.height + 40) duration:4 + (arc4random_uniform(100) + 1)/ 100.f];
    USAction *remove = [USAction run:^{
        [node removeFromSuperview];
    }];
    USAction *combine = [USAction sequence:@[move, remove]];
    [node run:combine];
}
- (UIView *)dropNode {
    UIImageView *node = [[UIImageView alloc] initWithFrame:CGRectMake(arc4random_uniform((int)self.view.bounds.size.width) + 1, -40, 40, 40)];
    node.image = [UIImage imageNamed:@"miss"];
    return node;
}

安装

pod repo update
pod 'USAction'

Latest podspec

{
    "name": "USAction",
    "version": "1.0",
    "summary": "u7c7bu4f3cSpriteKitu7684SKActionuff0cu4f60u53efu4ee5u5728UIKitu4e0au4f7fu7528USActionuff0cu7528u6cd5u540cSpriteKitu7684",
    "homepage": "https://github.com/Insfgg99x/USAction",
    "license": "MIT",
    "authors": {
        "CGPointZero": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Insfgg99x/USAction.git",
        "tag": "1.0"
    },
    "frameworks": [
        "Foundation",
        "UIKit"
    ],
    "platforms": {
        "ios": "6.0"
    },
    "source_files": "USAction/*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This