I have been fiddling around with the new Xcode 5 GM and UIDynamics to create an effect like the new "Bubble" Wallpaper on the iPhone Dashboard.
I want basically the same thing. certain Images added as a subview inside a custom UIView and added as an UIDynamicItem to a UIGravityBehavior to a UIDynamicAnimator. But still it does not seem to really work.
Main ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.image = [[MYImageView alloc] initWithFrame:CGRectMake(70, 200, 200, 200)];
[self.view addSubview:self.image];
UIDynamicAnimator *dynamicAnimator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
UIGravityBehavior *gravity = [[UIGravityBehavior alloc] init];
[dynamicAnimator addBehavior:gravity];
[gravity addItem:self.image];
self.view.alpha = 0.5f;
}
return self;
}
MYImageView.h
@interface NoteView : UIView <UIDynamicItem>
@property(nonatomic, readonly) CGRect bounds;
@property(nonatomic, readwrite) CGPoint center;
@property(nonatomic, readwrite) CGAffineTransform transform;
In the .m I just create an ImageView and add it to self as a subview. The bounds of self will be returned as double the size of the imageView added.
I get no errors and the App shows up fine, but I don't get any gravitational reaction.
Thanks for the help! Benzy