Deslizar hacia la derecha SOLAMENTE después de al menos un deslizamiento hacia la izquierda
Frecuentes
Visto 35 equipos
0
I am using left and right swipe for 'next image' and 'previous image'. On startup of the app I want to disable right swipe(previous) until at least one left swipe - is there any obvious way to do that?
1 Respuestas
0
You can create a simple method to handle swipes from all UISwipeGestureRecognizer instances. This method will enable/disable the gesture recognizers by itself.
Considering that you have two recognizers, namely
UISwipeGestureRecognizer *swipeRight;
UISwipeGestureRecognizer *swipeLeft;
And an array of images to be shown
NSArray *arrImages;
You will also need to maintain a global ivar
NSInteger currIndex; //To maintain the index
Both should have the same method as their selector, which is as follows:
-(void)handleSwipeFrom:(UISwipeGestureRecognizer*)recognizer
{
NSInteger newIndex = currIndex;
if ([recognizer isEqual: swipeLeft])
{
newIndex ++;
}
else if ([recognizer isEqual: swipeRight])
{
newIndex --;
}
if (newIndex >= 0 && newIndex <= ([arrImages count] - 1))
[self showImageAtIndex:newIndex];
}
The showImageAtIndex: method can handle the rest as follows:
-(void) showImageAtIndex: (NSInteger)index
{
if (index == 0)
{
[swipeRight setEnabled:NO];
}
else
{
[swipeRight setEnabled:YES];
}
if (index == ([arrImages count] - 1))
{
[swipeLeft setEnabled:NO];
}
else
{
[swipeLeft setEnabled:YES];
}
currIndex = index;
//Show image at currIndex here
}
For this to work perfectly, you need to instantiate currIndex and call showImageAtIndex in viewDidLoad:
currIndex = 0;
[self showImageAtIndex: currIndex];
contestado el 28 de mayo de 14 a las 12:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas objective-c or haz tu propia pregunta.
What did you try? Did you search Google before coming here? See ¿Cómo hago una buena pregunta? - Guillaume Algis
I have searched around yes, but find it rather difficult what exactly to search for. Have triends things such as: objective c +'disable function until' 'disable function conditional' etc - user3649561
I found a solution by moving the code where the function for right swipe is defined into the action of the left swipe - so that the right swipe is not defined until the first left swipe has been done by the user - user3649561
This method is not very clean, please look at my answer. - ZeMoon