我需要點擊按鈕時往右移動視圖,寫的代碼沒有實現:
UIView* view = [self.view viewWithTag:100];
if (!view) {
NSLog(@"nil");
}
[UIView animateWithDuration:0.3f
animations:^{
[view setTransform:CGAffineTransformMakeTranslation(-100, 0)];
}
completion:^(BOOL finished){
}
];
用這段代碼試試:
UIView* view = [self.view viewWithTag:100];
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^
{
CGRect frame = view.frame;
frame.origin.y = 0;
frame.origin.x = (-100);
view.frame = frame;
}
completion:^(BOOL finished)
{
NSLog(@"Completed");
}];