1

У меня есть кнопки на каком-то viewController view. touchUpInside: методы представляют модальные контроллеры. Я хочу представить их из центра нажатой кнопки. Как я могу достичь этого результата? Я пробовал:Существующий модальный контроллер с указанной точки

webController.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, self.buuton.center.x, self.button.center.y); 
     [self presentViewController:webController animated:NO completion:^{ 
      // some code 
     }]; 

но это повредило мой пользовательский интерфейс. Я также попытался использовать [UIView beginAnimation], без успеха.

ответ

0

Вы должны сделать это через addSubview: метод и делать что-то вроде:

- (void) appear: (UIView *) view fromPoint: (CGPoint) point 
{ 
    [view setBounds:self.view.bounds]; 
    [view setCenter:point]; 
    [view setAlpha:0.0]; 
    [self addSubview:view]; 
    [view setTransform:CGAffineTransformMakeScale(0, 0)]; 

    [UIView animateWithDuration:0.3 animations:^{ 
     [view setCenter:self.view.center]; 
     [view setTransform:CGAffineTransformIdentity]; 
     [view setAlpha:1.0]; 
    }]; 
} 

Вы должны создать представление, прежде чем вызывать метод.

Удачи!

1

Я достиг чего-то подобного с трюком, добавив destvc.view как subview в sourcevc.view, см. Ниже мои функции для масштабирования и масштабирования.

Вы можете использовать тот же трюк только визуальный эффект, и представить свой виртуальный канал в конце концов, без анимации:

+(void) animWithAlpha:(float)alpha view:(UIView*)view{ 
      [UIView animateWithDuration:0.15 
          delay:0.0 
         options:UIViewAnimationOptionBeginFromCurrentState 
        animations:^{ 
         view.alpha = alpha; 
        } 
        completion:^(BOOL fin) {}]; 
    } 


    +(void) zoomIN:(UIViewController*)sourceViewController destination:(UIViewController*)destinationViewController fromPoint:(CGPoint)point{ 

     [sourceViewController.view addSubview:destinationViewController.view]; 
     [destinationViewController.view setFrame:sourceViewController.view.window.frame]; 
     [destinationViewController.view setTransform:CGAffineTransformMakeScale(0.15, 0.1)]; 
     destinationViewController.view.center = point; 
     sourceViewController.view.userInteractionEnabled=NO; 
     destinationViewController.view.alpha = 0.5; 
     [self animWithAlpha:1 view:destinationViewController.view]; 
     [UIView animateWithDuration:0.4 
           delay:0.0 
          options:UIViewAnimationOptionCurveEaseInOut 
         animations:^{ 
          [destinationViewController.view setTransform:CGAffineTransformMakeScale(1, 1)]; 
          destinationViewController.view.center = sourceViewController.view.center; 
         } 
         completion:^(BOOL finished){ 
          if(finished){ 
           [destinationViewController.view setTransform:CGAffineTransformMakeScale(1, 1)]; 
           destinationViewController.view.center = sourceViewController.view.center; 
           sourceViewController.view.userInteractionEnabled=YES; 
          } 
         }]; 

    } 

    +(void) zoomOUT:(UIViewController*)sourceViewController destination:(UIView*)destination toPoint:(CGPoint)point{ 
     [sourceViewController.view setTransform:CGAffineTransformMakeScale(1.0, 1.0)]; 
     [sourceViewController.parentViewController.view setUserInteractionEnabled:NO]; 
     [destination setUserInteractionEnabled:NO]; 
     [UIView animateWithDuration:0.4 
           delay:0.0 
          options:UIViewAnimationOptionCurveEaseOut 
         animations:^{ 
          [sourceViewController.view setTransform:CGAffineTransformMakeScale(0.01, 0.01)]; 
          [sourceViewController.view setAlpha:1.0]; 
          sourceViewController.view.center = point; 
         } 
         completion:^(BOOL finished){ 
          if(finished){ 
           [sourceViewController.view setTransform:CGAffineTransformMakeScale(1.0, 1.0)]; 
           [sourceViewController.view removeFromSuperview]; 
           sourceViewController.view.center = point; 
           [destination setUserInteractionEnabled:YES]; 
          } 
    } 
+0

Что такое 'animWithAlpha: вид:'? И как вы можете использовать self в методе '+' class? –

+0

Извините, я пропустил это, он работает, потому что animwithalpha также является классом. Я обновил код –

Смежные вопросы