0
点赞
收藏
分享

微信扫一扫

IOS 控件带动画移动

谷中百合517 2023-02-17 阅读 84

-(IBAction)move:(UIButton *) button {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
// 不允许直接修改某个对象的结构体成员
CGRect tempFrame = self.image.frame;
if (button.tag == 1) {
// 上
NSLog(@"上");
tempFrame.origin.y = tempFrame.origin.y - 10;
} else if (button.tag == 2) {
// 右
NSLog(@"右");
tempFrame.origin.x = tempFrame.origin.x + 10;
} else if (button.tag == 3) {
// 下
NSLog(@"下");
tempFrame.origin.y = tempFrame.origin.y + 10;
} else if (button.tag == 4) {
// 左
NSLog(@"左");
tempFrame.origin.x = tempFrame.origin.x - 10;
}
self.image.frame = tempFrame;

[UIView commitAnimations];
}

举报

相关推荐

0 条评论