2014-09-02 48 views
3

動畫左/右輕掃觀點儘量讓輕掃在單一視圖和它的工作,但沒有得到在底部如何使用UISwipeGestureRecognizer

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
UISwipeGestureRecognizer *swipeleft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(screenswipeleft)]; 
swipeleft.numberOfTouchesRequired=1; 
swipeleft.direction=UISwipeGestureRecognizerDirectionLeft; 
[self.view addGestureRecognizer:swipeleft]; 

UISwipeGestureRecognizer *swiperight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(viewDidLoad)]; 
swiperight.numberOfTouchesRequired=1; 
swiperight.direction=UISwipeGestureRecognizerDirectionRight; 
[self.view addGestureRecognizer:swiperight]; 

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)]; 
[self.view addSubview:textField]; 
NSLog(@"move left"); 

} 
-(void)screenswipeleft { 
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)]; 
[self.view addSubview:textField]; 
NSLog(@"move right"); 

} 

回答

1
- (void)viewDidLoad 
    { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    _leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)]; 
    _rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)]; 

    _leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft; 
    _rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight; 

    [self.view addGestureRecognizer:_leftSwipeGestureRecognizer]; 
    [self.view addGestureRecognizer:_rightSwipeGestureRecognizer]; 
} 

- (void)handleSwipes:(UISwipeGestureRecognizer *)sender 
{ 
    if (sender.direction == UISwipeGestureRecognizerDirectionLeft) { 
    CGPoint labelPosition = CGPointMake(self.swipeLabel.frame.origin.x - 100.0, self.swipeLabel.frame.origin.y); 
    self.swipeLabel.frame = CGRectMake(labelPosition.x , labelPosition.y , self.swipeLabel.frame.size.width, self.swipeLabel.frame.size.height); 

    } 

    if (sender.direction == UISwipeGestureRecognizerDirectionRight) { 
     CGPoint labelPosition = CGPointMake(self.swipeLabel.frame.origin.x + 100.0, self.swipeLabel.frame.origin.y); 
     self.swipeLabel.frame = CGRectMake(labelPosition.x , labelPosition.y , self.swipeLabel.frame.size.width, self.swipeLabel.frame.size.height); 
    } 
} 
+0

感謝,這是很好的,但是,我有20個標籤,一個I部分他們2圖10-10標籤的話,我需要刷卡的導航他們的動畫這一觀點和一個指示燈放在底部。 – 2014-09-02 17:30:02

+0

你確切的要求是什麼? – 2014-09-03 05:18:04

+0

從右到左和從左到右滑動2個視圖,以及一個用於瀏覽兩個視圖的指示器,就像android菜單一樣,當我們滑動它時,它會顯示下一個菜單圖標視圖。我在我的註冊表格中執行該操作。 – 2014-09-03 05:44:01

0

動畫和網頁indicatore泡沫試試這個。

-(void)screenswipeleft 
{ 
    [UIView beginAnimations:nil context:nil]; 
         [UIView setAnimationDuration:0.4]; 

         textField.frame = CGRectMake(10, 200, 300, 40)]; 


         [UIView commitAnimations] 



} 
2

假設您想爲UITextField設置動畫。 而你的UITextField有一個起始點爲x - 50,y - 100的CGRect;

@implementation myViewController{ 
    UITextField *myTextField; //Declaring a textfield as an instance variable (global). 
} 


    -(void)viewDidLoad{ 
    myTextField = [UITextField alloc]initWithFrame:CGRectMake(50,100,100,50)];//adding memory and setting its initial position 
    //your other codes. 
} 
    -(void)screenswipeleft { 
    [UIView animateWithDuration:3 animations:^{ 
     myTextField.frame = CGRectMake:(-75,100,100,50); //setting the same textfield in a position of -75 only showing 1/4th of the textfield. 
//this block animation would make the textfield animate from its starting position to this position in 3 seconds. (animateWithDuration:3 here u mention its duration). 
    }]; 
    } 

對其他人應用相同的邏輯,你會得到你想要的動畫。

相關問題