我試圖從平滑幻燈片類型動畫中的UIViewController頂部的起始位置移動UILabel,以便在視圖加載後從頂部向下滑動,然後在ay位置約10秒。 10秒後,我想再次滑回視圖。將UILabel滑動到視圖控制器
-(void) animateInstructionLabel
{
float newX = 50.0f;
float newY = 100.0f;
[UIView transitionWithView:self.lblInstruction
duration:10.0f
options:UIViewAnimationCurveEaseInOut
animations:^(void) {
lblInstruction.center = CGPointMake(newX, newY);
}
completion:^(BOOL finished) {
// Do nothing
}];
}
但我不知道如何做10秒延遲,然後回到上面的方法。最終的結果是,我希望這是一個看起來像通知一樣的標籤,然後再移出屏幕。
有人能幫我把上述這些碎片放在一起嗎?
編輯
我加入這基於以下答案:
-(void) animateInstructionLabel
{
float newX = lblInstruction.frame.origin.x;
float newY = 20.0f;
lblInstruction.center = CGPointMake(lblInstruction.frame.origin.x, -20.0f);
lblInstruction.bounds = CGRectMake(lblInstruction.frame.origin.x, -20.0f, 650.0f, 40.0f);
[UIView animateWithDuration:3.0f
delay:0
options:UIViewAnimationCurveEaseInOut
animations:^(void) {
lblInstruction.center = CGPointMake(newX, newY);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:5.0f
delay:5.0
options:UIViewAnimationCurveEaseInOut
animations:^(void) {
lblInstruction.center = CGPointMake(newX, -20);
}
completion:^(BOOL finished) {
// Do nothing
}
];
}
];
}
但即使我的動畫開始我看到的是運動之前設置label.center關閉屏幕從viewcontroller的左上角到viewcontroller的中心。它不保留在動畫開始之前應該設置的x位置。
感謝您的回覆。這工作。唯一的問題是我的立場。它從ViewController的頂部向左移動50.0f,即從左上角移動到ViewController的中心。我希望它從頂部下降,然後垂直向上滑動,而不會從左到右移動。 – motionpotion
在動畫開始之前,您需要確保標籤的中心在屏幕尚未離開屏幕時正確設置。 – rmaddy
我已經添加了以下內容來嘗試在動畫開始之前設置位置,但似乎沒有設置此位置。例如lblInstruction.center = CGPointMake(lblInstruction.frame.origin.x,-20.0f); lblInstruction.bounds = CGRectMake(lblInstruction.frame.origin.x,-20.0f,650.0f,40.0f);但它仍然從左上角移動到新位置,然後返回到左上角。我在xib上設置的確切位置是-20.0f(x)187.0f(y)。 – motionpotion