我正在做一些自定義動畫以在單一方法中更改視圖。我已經使用[UIView setAnimationDidStopSelector:@selector(removeFromSuperview)]
從superView中刪除了「fromView」,但我也希望在動畫結束後啓用用戶交互。從超級視圖中移除並啓用用戶交互
這裏是我的代碼:
-(void) switchFrom:(UIViewController*) fromViewController To:(UIViewController*) toViewController usingAnimation:(int) animation{
UIView *fromView = fromViewController.view;
UIView *toView = toViewController.view;
/*************** SET ALL DEFAULT TRANSITION SETTINGS ***************/
// Get the current view frame, width and height
CGRect pageFrame = fromView.frame;
CGFloat pageWidth = pageFrame.size.width;
// Create the animation
[UIView beginAnimations:nil context:nil];
// Create the delegate, so the "fromView" is removed after the transition
[UIView setAnimationDelegate: fromView];
[UIView setAnimationDidStopSelector:@selector(removeFromSuperview)];
// Set the transition duration
[UIView setAnimationDuration: 0.4];
/*************** IT DOESN'T WORK AT ALL ***************/
[toView setUserInteractionEnabled:NO];
[UIView setAnimationDelegate: toView];
[UIView setAnimationDidStopSelector:@selector(setUserInteractionEnabled:)];
[toView setUserInteractionEnabled:YES];
// Add the "toView" as subview of "fromView" superview
[fromView.superview addSubview:toView];
switch (animation) {
case AnimationPushFromRigh:{
// Position the "toView" to the right corner of the page
toView.frame = CGRectOffset(pageFrame, pageWidth,0);
// Animate the "fromView" to the left corner of the page
fromView.frame = CGRectOffset(pageFrame, -pageWidth,0);
// Animate the "toView" to the center of the page
toView.frame = pageFrame;
// Animate the "fromView" alpha
fromView.alpha = 0;
// Set and animate the "toView" alpha
toView.alpha = 0;
toView.alpha = 1;
// Commit the animation
[UIView commitAnimations];
}
.
.
.
任何想法,我怎麼能叫在setAnimationDidStopSelector
這兩種方法,實際上使他們一起工作?
EDIT 1
試過@safecase這樣的代碼,替換此評論塊:
/*************** IT DOESN'T WORK AT ALL ***************
[toView setUserInteractionEnabled:NO];
[UIView setAnimationDelegate: toView];
[UIView setAnimationDidStopSelector:@selector(setUserInteractionEnabled:)];
[toView setUserInteractionEnabled:YES];
*************** IT DOESN'T WORK AT ALL ***************/
// Remove the interaction
[toView setUserInteractionEnabled:NO];
[fromView setUserInteractionEnabled:NO];
// Create the animation
[UIView animateWithDuration:0.4 animations:^{
[fromView performSelector:@selector(removeFromSuperview)];
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.4
animations:^{
C6Log(@"finished");
[toView performSelector: @selector(setUserInteractionEnabled:)];
}];
}];
的 「toView」 被刪除,而不是 「fromView」 除去:( 按鈕繼續在動畫過程中需要互動
但我需要兩個「發件人」... toView(從superView中刪除)和fromView(以啓用交互)。 我可以設置兩個不同的「setAnimationDidStopSelector」嗎?它會起作用嗎? –
是不是「從視圖」原來的超視圖?如果是這樣,爲什麼不在上述方法中使用這種關係? – Till
@Till,實際上,有一個「mainView」superview ...我可以嘗試這樣的... –