如何设置animation到UIImageView?
如何给UIImageView提供animation。 我有一个以下的animation代码,但不适用于imageview
MyImage=[[UIImageView alloc] initWithFrame:CGRectMake(10, 57, 220,140)]; MyImage.image=[UIImage imageNamed:@"image.png"]; MyImage.userInteractionEnabled = YES; [self.view addSubview:MyImage]; [UIView beginAnimations : nil context : nil]; [UIView setAnimationCurve : UIViewAnimationCurveLinear]; [UIView setAnimationDuration : 1.00]; UIView setAnimationTransition : UIViewAnimationTransitionFlipFromLeft forView : MyImage cache : YES]; [UIView commitAnimations];
有人有想法让我知道..谢谢
UIView setAnimationTransition : UIViewAnimationTransitionFlipFromLeft forView : MyImage cache : YES];
松散[
之前的代码? 也许这是types错误。
我想你可能会喜欢这个,基于块的animation更好;):
[UIView transitionFromView:self.view toView:MyImage duration:1.0f options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
这里的代码片段效果很好:
MyImage=[[UIImageView alloc] initWithFrame:CGRectMake(10, 57, 220,140)]; MyImage.image=[UIImage imageNamed:@"NTCHomeMainPic.png"]; MyImage.userInteractionEnabled = YES; // [self.view addSubview:MyImage]; // You don't need to add it as subview, but never mind [UIView transitionFromView:self.view toView:MyImage duration:1.0f options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
编辑:
您需要创build一个新的视图,并将MyImage
添加到它。 新版本如下:
UIView * newView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)]; [newView setBackgroundColor:[UIColor whiteColor]]; UIImageView * MyImage=[[UIImageView alloc] initWithFrame:CGRectMake(10, 57, 220,140)]; MyImage.image=[UIImage imageNamed:@"NTCHomeMainPic.png"]; MyImage.userInteractionEnabled = YES; [newView addSubview:MyImage]; [UIView transitionFromView:self.view toView:newView duration:1.0f options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];