2014-02-20 4 views
0

enter image description hereIOS Pandora как нижняя панель

Каждый знает, как реализовать функцию перетаскивания на панели инструментов, чтобы сделать еще один вид появляется? Возможно, добавление subview на панель инструментов, но я не уверен, как я должен сложить это или обработать перетаскивание.

ответ

3

Вам нужно Что-то вроде this video?

  • Вот пример

    enter image description here

  • Вот другой

    enter image description here

это вот мой подход к реализации этого:

  • Создать панель инструментов.
  • Создание BottomView (должно быть позади Toolbar.
  • Добавить SwipteGestures с Up & вниз направление на ToolBar
  • В целевом методе, просто сделать анимацию, чтобы двигаться вверх & вниз.

Вот код, который я написал всего несколько минут назад.

// add the variables 
    UIToolbar *myToolBar; 
    UIView *hiddenView; 
    BOOL movedUP; 


    -(void)addToolBar{ 
     [self addBottomMostHiddenView]; 
     UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 
     [self.navigationController.toolbar setBarStyle:UIBarStyleBlackOpaque]; 
     UIBarButtonItem *one = [[UIBarButtonItem alloc] initWithTitle:@"One Item" style:UIBarButtonItemStylePlain target:self  action:nil]; 
     UIBarButtonItem *drag = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon-drag-64.png"] style:UIBarButtonItemStylePlain target:self action:nil]; 
    drag.enabled = NO; 
     UIBarButtonItem *two = [[UIBarButtonItem alloc] initWithTitle:@"Two Item" style:UIBarButtonItemStylePlain target:self  action:nil]; 
     NSArray *toolbarItems = [NSArray arrayWithObjects:one,spaceItem, drag, spaceItem , two, nil]; 

     myToolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 430, self.view.frame.size.width, 80)]; 
     myToolBar.tintColor = [UIColor whiteColor]; 
     myToolBar.barTintColor = [UIColor colorWithRed:53.0/255.0 green:70.0/255.0 blue:103.00/255.00 alpha:1]; 
     [self.view addSubview:myToolBar]; 
     [myToolBar setItems:toolbarItems animated:YES]; 

     UISwipeGestureRecognizer *upGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(dragMe:)]; 
    upGesture.direction = UISwipeGestureRecognizerDirectionUp; 
     [myToolBar addGestureRecognizer:upGesture]; 

     UISwipeGestureRecognizer *downGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(dragMe:)]; 
    downGesture.direction = UISwipeGestureRecognizerDirectionDown; 
     [myToolBar addGestureRecognizer:downGesture]; 

    } 


    -(void)addBottomMostHiddenView{ 
     hiddenView = [[UIView alloc]initWithFrame:CGRectMake(0, 510, self.view.frame.size.width, 40)]; 
     UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconProgress.png"]]; 
     [hiddenView addSubview:image]; 
     [hiddenView setBackgroundColor:[UIColor colorWithWhite:0.2 alpha:0.8]]; 
     [self.view addSubview:hiddenView]; 
    } 

    -(void)dragMe:(UISwipeGestureRecognizer *)gesture { 
     [UIView animateWithDuration:0.5 animations:^{ 
      if(gesture.direction == UISwipeGestureRecognizerDirectionDown) { 
       if(movedUP) { 
        myToolBar.frame = CGRectMake(0, 430, self.view.frame.size.width, 80); 
        hiddenView.frame = CGRectMake(0, 510, self.view.frame.size.width, 80); 
        movedUP = NO; 
       } 
     }else if(gesture.direction == UISwipeGestureRecognizerDirectionUp) { 
      if(!movedUP) { 
       myToolBar.frame = CGRectMake(0, 390, self.view.frame.size.width, 80); 
       hiddenView.frame = CGRectMake(0, 470, self.view.frame.size.width, 80); 
       movedUP = YES; 
      } 
     } 
    }]; 

} 

Надежда, что помогает у ОУ.

+0

Проще задайте кадр расчетным способом, а не способом жестких кодов. Я просто сделал это, чтобы дать вам ключ. –

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