2015-03-04 3 views
0

Я пытаюсь обновить унаследованный проект xCode. По сути, я рисую пробел при прикреплении действия к жестом салфетки, который я включил в проект. Я только когда-либо делал это с раскадрой, но из-за возраста проекта это не вариант.Изменение UiView без viewcontroller с помощью swipe

В настоящее время у меня есть контроллер вида, в котором есть всплывающее окно отдельного UIView. Пользователь должен затем прокручивать назад и вперед через три страницы содержимого. Существует еще одно всплывающее окно, но это только одна страница и, следовательно, не требует функциональности. Я вижу, что устройство распознает мой swipe (через вывод), но я не знаю, как приложить действие, чтобы перейти к другим представлениям пользовательского интерфейса, хранящимся в контроллере ....... Или, если это даже возможно и Мне придется переосмыслить, как я это сделал. Любая помощь приветствуется.

Благодаря

+0

Вы уже смотрели на 'UIPageViewController'? https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPageViewControllerClassReferenceClassRef/ – KIDdAe

+0

На SO есть несколько хороших ссылок, которые помогут вам задать ответный вопрос. (см. здесь http://stackoverflow.com/help/mcve). – danh

ответ

0

Вы действительно должны использовать UIPageViewController, но вот пример кода, если вы не хотите использовать один:

@interface ViewController() 

@property (strong, nonatomic) UIView *view1; 
@property (strong, nonatomic) UIView *view2; 
@property (strong, nonatomic) UIView *view3; 
@property (nonatomic) BOOL isSwipeEnabled; 

@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    self.isSwipeEnabled = YES; 

    self.view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
    self.view1.backgroundColor = [UIColor redColor]; 
    [self.view addSubview:self.view1]; 

    self.view2 = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.view1.frame), 0, self.view.frame.size.width, self.view.frame.size.height)]; 
    self.view2.backgroundColor = [UIColor yellowColor]; 
    [self.view addSubview:self.view2]; 

    self.view3 = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.view2.frame), 0, self.view.frame.size.width, self.view.frame.size.height)]; 
    self.view3.backgroundColor = [UIColor blueColor]; 
    [self.view addSubview:self.view3]; 

    UISwipeGestureRecognizer *leftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)]; 
    leftGesture.direction = UISwipeGestureRecognizerDirectionLeft; 
    [self.view addGestureRecognizer:leftGesture]; 

    UISwipeGestureRecognizer *rightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)]; 
    rightGesture.direction = UISwipeGestureRecognizerDirectionRight; 
    [self.view addGestureRecognizer:rightGesture]; 
} 

-(void)swipeHandler:(UISwipeGestureRecognizer*)recognizer 
{ 
    self.isSwipeEnabled = NO; 
    if(recognizer.direction == UISwipeGestureRecognizerDirectionLeft) 
    { 
     if (self.view3.frame.origin.x > 0) { 
      [self updateMyViewsToXPosition:self.view1.frame.origin.x - self.view.frame.size.width]; 
     } 
    } 
    else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) 
    { 
     if (self.view1.frame.origin.x != 0) { 
       [self updateMyViewsToXPosition:self.view1.frame.origin.x + self.view.frame.size.width]; 
     } 

    } else { 
     self.isSwipeEnabled = YES; 
    } 
} 

- (void)updateMyViewsToXPosition:(CGFloat)xPos 
{ 
    [UIView animateWithDuration:0.3 animations:^{ 

     self.view1.frame = CGRectMake(xPos, 0, self.view1.frame.size.width, self.view1.frame.size.height); 
     self.view2.frame = CGRectMake(CGRectGetMaxX(self.view1.frame), 0, self.view.frame.size.width, self.view.frame.size.height); 
     self.view3.frame = CGRectMake(CGRectGetMaxX(self.view2.frame), 0, self.view.frame.size.width, self.view.frame.size.height); 

    }completion:^(BOOL finished) { 
     self.isSwipeEnabled = YES; 
    }]; 
} 
Смежные вопросы