marquee - IOS scrollview is not clickable -
here code:
int = 0; self.userinteractionenabled = yes; self.exclusivetouch = yes; self.cancancelcontenttouches = yes; self.delayscontenttouches = yes; self.translatesautoresizingmaskintoconstraints = yes; uitapgesturerecognizer *tapgesturerecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(gototest)]; tapgesturerecognizer.numberoftapsrequired = 1; [self addgesturerecognizer:tapgesturerecognizer]; (nsstring *message in self.messages) { uilabel * label = [[uilabel alloc] initwithframe:cgrectzero]; self.userinteractionenabled = yes; label.text = message; label.tag = i; cgsize size = [message sizewithfont:label.font]; cgfloat width = size.width + kpadding; label.frame = cgrectmake(xpos, 0.0, width, self.frame.size.height); [self addsubview:label]; i++; xpos += width; nslog(@"%@",nsstringfromcgrect(label.frame)); } self.messageswidth = xpos; self.contentsize = cgsizemake(xpos, self.frame.size.height); self.contentoffset = cgpointmake(-self.frame.size.width, 0.0); } -(void)gototest { nslog(@"test %@",@"ccc "); }
and marquee - (void)go {
if (!self.period) self.period = self.messageswidth / 100; // takes same (fudged, reasonable) amount of time scroll whole array [uiview animatewithduration:self.period delay:0.0 options:uiviewanimationoptioncurvelinear |uiviewanimationoptionrepeat animations:^{ self.contentoffset = cgpointmake(self.messageswidth, 0.0); } completion:^(bool finished){}]; }
so, goal create marquee news , each news clickable see details of clicked new.
but uitapgesturerecognizer doesnt work , dont know why.
note self scrollview because class extend uiscrollview.
so please me
you have subclass uiscrollview
in following way. use custom scroll view (i.e. touchscrollview
) instead of regular uiscrollview
touchscrollview.h:
#import <foundation/foundation.h> @import uikit; @interface touchscrollview : uiscrollview @end
touchscrollview.m:
#import "touchscrollview.h" @implementation touchscrollview - (void)touchesbegan:(nsset *)touches withevent:(uievent *)event { // respond touch events here // ... [self.nextresponder touchesbegan:touches withevent:event]; } - (void)touchesmoved:(nsset *)touches withevent:(uievent *)event { [self.nextresponder touchesmoved:touches withevent:event]; } - (void)touchesended:(nsset *)touches withevent:(uievent *)event { [self.nextresponder touchesended:touches withevent:event]; } @end
or if want in swift since it's fashion nowadays:
touchscrollview.swift
import foundation import uikit class touchscrollview: uiscrollview { override func touchesbegan(touches: nsset!, withevent event: uievent!) { // respond touch events here // ... nextresponder().touchesbegan(touches, withevent: event) } override func touchesmoved(touches: nsset!, withevent event: uievent!) { nextresponder().touchesmoved(touches, withevent: event) } override func touchesended(touches: nsset!, withevent event: uievent!) { nextresponder().touchesended(touches, withevent: event) } }
Comments
Post a Comment