IOS 控制元件帶動畫移動
阿新 • • 發佈:2019-02-12
-(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]; }