我有這個問題,我已經設置了並且在觸摸其中的一個之後他們必須移動,所以我使用動畫實現了此功能,並且工作正常。但在動畫完成後,我正在執行一個模態賽格,問題在於模態賽格開始時,從底部提高新的UIView
,返回到他們以前的位置,在那裏我將它們設置在Storyboard
中,並且它看起來很糟糕。我怎麼解決這個問題? 下面是我使用在動畫之後執行塞格動畫,但動畫物品恢復到原來的位置
@property (strong, nonatomic) IBOutlet UIButton *maleBtn;
@property (strong, nonatomic) IBOutlet UIButton *femaleBtn;
- (void)viewDidLoad
{
[super viewDidLoad];
[_maleBtn addTarget:self
action:@selector(chooseGender:)
forControlEvents:UIControlEventTouchUpInside];
[_femaleBtn addTarget:self
action:@selector(chooseGender:)
forControlEvents:UIControlEventTouchUpInside];
}
- (IBAction)chooseGender:(id)sender
{
CGRect maleFrame;
CGRect femaleFrame;
if (sender == _maleBtn) {
maleFrame = self.maleBtn.frame;
maleFrame.origin.x = (self.view.bounds.size.width/2) - 15;
femaleFrame = self.femaleBtn.frame;
femaleFrame.origin.x = self.view.bounds.size.height;
}
else {
maleFrame = self.maleBtn.frame;
maleFrame.origin.x = -self.view.bounds.size.height;
femaleFrame = self.femaleBtn.frame;
femaleFrame.origin.x = (self.view.bounds.size.width/2) - 15;
}
[UIView animateWithDuration:0.5
delay:0.5
options:UIViewAnimationCurveEaseOut
animations:^{
_maleBtn.frame = maleFrame;
_femaleBtn.frame = femaleFrame;
}
completion:^(BOOL finished){
if(sender == _maleBtn)
[self performSegueWithIdentifier:@"toMale" sender:self];
else
[self performSegueWithIdentifier:@"toFemale" sender:self];
}];
}
你有什麼東西在你的viewWillAppear?你有沒有嘗試過使用CGRectMake進行定位? –
沒有這是我的所有.m沒有別的,只是我在故事板中的那些位置設置按鈕 – r4id4
只需要在你的完成嘗試它,把它放在:_maleBtn.frame = CGRectMake(100,100,20,20) ;在賽前。執行搜尋並關閉並查看按鈕是否已變回原始位置。或者如果它調整大小並移動。 –