
####iOS7 Programming Cookbook 第二章学习笔记 UIGravityBehavior
#####Adding Gravity to your UI components

#####ViewController.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
@interface ()
@property (nonatomic, strong) UIView *squareView;
@property (nonatomic, strong) UIDynamicAnimator *animator; @end
@implementation
- (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; self.squareView = [[UIView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)]; self.squareView.backgroundColor = [UIColor greenColor]; self.squareView.center = self.view.center; [self.view addSubview:self.squareView]; self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view]; UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[self.squareView]]; [self.animator addBehavior:gravity]; }
@end
|
Reference
近期评论