2013-12-10 17 views
5

Sto avendo queste 2 funzioni nella mia FYImageSequence.m file.I ereditato la classe da UIImageViewtouchesBegan e touchesMoved funzioni non lavorare su UIImageView

@interface FVImageSequence : UIImageView 

mi è stato in grado di collegare questo al mio UIImageView in storyboard.But come rendere le funzioni sotto funzionanti. Ci sono delle connessioni che dovrebbero essere fatte.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
if(increment == 0) 
    increment = 1; 
    [super touchesBegan:touches withEvent:event]; 

    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint touchLocation = [touch locationInView:self]; 
    previous = touchLocation.x; 
} 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
[super touchesMoved:touches withEvent:event]; 

    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint touchLocation = [touch locationInView:self]; 
int location = touchLocation.x; 

if(location < previous) 
    current += increment; 
else 
    current -= increment; 

previous = location; 

if(current > numberOfImages) 
    current = 0; 
if(current < 0) 
    current = numberOfImages; 

NSString *path = [NSString stringWithFormat:@"%@%d", prefix, current]; 
NSLog(@"%@", path); 

path = [[NSBundle mainBundle] pathForResource:path ofType:extension]; 


UIImage *img = [[UIImage alloc] initWithContentsOfFile:path]; 

[self setImage:img]; 
} 

risposta

9

L'interazione utente di UIImageView è predefinita NO. Quindi è necessario renderlo SI come questo

self.userInteractionEnabled = YES; 
2

Set UserInteractionEnabled-YES sulla visualizzazione dell'immagine.

0

Per questo, ho dovuto utilizzare il metodo, e non la variabile (in qualche modo la variabile non era accessibile direttamente), così:
[auto setUserInteractionEnabled: SÌ];

Problemi correlati