如何移动UIImageView?

发布于 2024-09-28 07:11:54 字数 1807 浏览 1 评论 0原文

交易如下: 我在 viewDidLoad 中编写了一个 UIImageView 代码,我希望它能随着我的功能 buttonPressed** 向下移动,而无需像我一样创建其他子视图。

这是代码。

-(void)viewDidLoad {

[super viewDidLoad];

banetteImage = [UIImage imageNamed:@"myBanette.png"];

UIImageView *banetteView = [[UIImageView alloc] initWithImage:banetteImage];
banetteView.frame = CGRectMake(100, -740, 568, 790);
banetteView.opaque = NO;

[NSTimer SchedulerWithTimeInterval:2.5 target:self 选择器:@selector(buttonPressed: ) userInfo:nil 重复:NO];

[self.view addSubview:banetteView];

}

-(void)buttonPressed {

double speed = 1 / round(random() % 100) + 1.0;

[UIView beginAnimations:nil context:banetteView];
[UIView setAnimationDuration: 2*speed ];

banetteView.frame = CGRectMake(100, -2, 568, 790);
banetteView.opaque = NO;

UIImageView *banetteView = [[UIImageView alloc] initWithImage:banetteImage];
banetteView2.frame = CGRectMake(100, -740, 568, 790);
banetteView.opaque = NO;
banetteView.hidden = YES;
[self.view addSubview:banetteView];

// set a stop callback so we can cleanup the banette when it reaches the
// end of its animation
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];

}

-(void)onAnimationComplete:(NSString *)animationID 完成:(NSNumber *)完成上下文:(void *)context {

UIImageView *banetteView = context;


double speed = 1 / round(random() % 100) + 1.0;
banetteView.frame = CGRectMake(100, -2, 568, 790);
banetteView2.opaque = NO;
[self.view addSubview:banetteView2];

[UIView beginAnimations:nil context:banetteView];
[UIView setAnimationDuration: 2*speed ];


[banetteView release];

}

Heres the deal:
I code an UIImageView in the viewDidLoad and i want it to move down with my fonction buttonPressed** without creating an other subview like i do.

Heres the code.

-(void)viewDidLoad {

[super viewDidLoad];

banetteImage = [UIImage imageNamed:@"myBanette.png"];

UIImageView *banetteView = [[UIImageView alloc] initWithImage:banetteImage];
banetteView.frame = CGRectMake(100, -740, 568, 790);
banetteView.opaque = NO;

[NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(buttonPressed: ) userInfo:nil repeats:NO];

[self.view addSubview:banetteView];

}

-(void)buttonPressed {

double speed = 1 / round(random() % 100) + 1.0;

[UIView beginAnimations:nil context:banetteView];
[UIView setAnimationDuration: 2*speed ];

banetteView.frame = CGRectMake(100, -2, 568, 790);
banetteView.opaque = NO;

UIImageView *banetteView = [[UIImageView alloc] initWithImage:banetteImage];
banetteView2.frame = CGRectMake(100, -740, 568, 790);
banetteView.opaque = NO;
banetteView.hidden = YES;
[self.view addSubview:banetteView];

// set a stop callback so we can cleanup the banette when it reaches the
// end of its animation
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];

}

-(void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

UIImageView *banetteView = context;


double speed = 1 / round(random() % 100) + 1.0;
banetteView.frame = CGRectMake(100, -2, 568, 790);
banetteView2.opaque = NO;
[self.view addSubview:banetteView2];

[UIView beginAnimations:nil context:banetteView];
[UIView setAnimationDuration: 2*speed ];


[banetteView release];

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文