3

try to make swipe in single-view and it's working but not get animation and page indicatore bubble in bottom

- (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");

}
Ganesh Kumar
  • 708
  • 6
  • 25
Ujesh Patel
  • 33
  • 1
  • 6

3 Answers3

2

Suppose you want to animate the UITextField. And your UITextField has a CGRect with starting point of x - 50, y - 100;

   @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).
    }];
   }

Apply same logic to others and you will get the animation you want.

Saheb Roy
  • 5,899
  • 3
  • 23
  • 35
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);
   }
}
BergQuester
  • 6,167
  • 27
  • 39
Ganesh Kumar
  • 708
  • 6
  • 25
  • thanks , it's good but,i have 20 label, an i part them in 2 view 10-10 label so , i need to swipe that view animated and one indicator put bottom for navigate them . – Ujesh Patel Sep 02 '14 at 17:30
  • what's your exact requirement? – Ganesh Kumar Sep 03 '14 at 05:18
  • swiping 2 view right to left and left to right , and one indicator for navigate that two view, just like android menu ,when we swipe it,it will show next menu icon view. i implement that in my registration form. – Ujesh Patel Sep 03 '14 at 05:44
  • you can use UIPageViewController for that purpose.Refer this link http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial – Ganesh Kumar Sep 03 '14 at 07:31
0

Try this.

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

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


                       [UIView commitAnimations]



}