sf1995 2015-10-17 01:58 采纳率: 0%
浏览 1657

我添加的UIGravityBehavior并没有动画显示

 //
//  ViewController.m
//  DropGame
//
//  Created by bayMax on 10/16/15.
//  Copyright © 2015 bayMax. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *gameView;
@property (strong,nonatomic) UIDynamicAnimator *animator;
@property (strong,nonatomic) UIGravityBehavior  *gravity;
@property (strong,nonatomic) UIPushBehavior *push;

@end

@implementation ViewController

static const CGSize DROP_SIZE = {40,40};

-(UIDynamicAnimator *)animaotr
{
    if(!_animator)
    {
        _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.gameView];
    }
    return _animator;
}
-(UIGravityBehavior *)gravity
{
    if(!_gravity)
    {
        _gravity = [[UIGravityBehavior alloc] init];
        _gravity.magnitude = 1;
        [self.animator addBehavior:_gravity];
    }
    return _gravity;
}
/*-(UIPushBehavior *)push
{
    if(!_push)
    {
        _push = [[UIPushBehavior alloc] init];
        [self.animator addBehavior:_push];
    }
    return _push;
}
*/
- (IBAction)tap:(UITapGestureRecognizer *)sender {
    [self drop];
}

-(void)drop
{
    CGRect frame;
    frame.origin = CGPointZero;
    frame.size = DROP_SIZE;
    int x = (arc4random()%(int)self.gameView.bounds.size.width) / DROP_SIZE.width;
    frame.origin.x = x * DROP_SIZE.width;

    UIView *dropView = [[UIView alloc] initWithFrame:frame];
    dropView.backgroundColor = [self randomColor];
    [self.gameView addSubview:dropView];
    [self.gravity addItem:dropView];
}
-(UIColor *)randomColor
{
    switch (arc4random()%5) {
        case 0:return [UIColor greenColor];break;
        case 1:return [UIColor redColor];break;
        case 2:return [UIColor blueColor];break;
        case 3:return [UIColor yellowColor];break;
        case 4:return [UIColor purpleColor];break;
    }
    return [UIColor blackColor];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

有UIDynamicAnimator我也添加了gravity但是就是没有动画,这是为什么。。

  • 写回答

1条回答 默认 最新

  • Leexianke 2015-10-19 00:18
    关注

    你都没有访问gravity,其中的方法永远不会调用

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?