English 中文(简体)
单管:家庭火灾
原标题:iPhone: UIControlEventTouchUpInside fires multiple times

** 解决。

任何人都可以向我表示,要强调对“全球风险信息”的控制?

What I want to achive is the highlight effect similar to UITableViewCell, when touched. In the following code I change the alpha value of a highlight view when the user touch up inside the control. Unfortunately the event is fired multiple times, when one holds the thumb on the display and moves it up or down (in my understanding it is a UIControlEventTouchDragInside gesture). What s wrong with it? Do I really have to remove the event target during the animation?

-(id)initWithFrame:(CGRect)frame_
{
   if (self = [super initWithFrame:frame_])
   {
      ...
      [self setMultipleTouchEnabled:NO];
      [self addTarget:self action:@selector(touchUpInside) forControlEvents:UIControlEventTouchUpInside];
   }
   return self;
}

-(void)touchUpInside
{
   [self setHighlighted:YES];
}

-(void)animationFinished
{
   // Remove the highlight animated
   [self setHighlighted:NO];
}

-(void)setHighlighted:(BOOL)highlighted_
{
   BOOL oldValue = [self isHighlighted];
   [super setHighlighted:highlighted_];
   if (highlighted_ != oldValue)
   {
      [UIView beginAnimations:nil context:nil];
      [UIView setAnimationDuration:0.35f];
      if (highlighted_)
      {  
         [UIView setAnimationDelegate:self];
         [UIView setAnimationDidStopSelector:@selector(animationFinished)];
         [[self highlightView] setAlpha:0.5f];
      }
      else
      {
         [[self highlightView] setAlpha:0.0f];
      }
      [UIView commitAnimations];
   }
   ...
}

The mutator setHighlighted:(BOOL)newState_ is invoked by the UI framework (multiple times while draging the thumb over a control). There is no need to track touch events to implement the highlighted state. Simplest solution is to override the mutator and mimic the new state...

-(void)setHighlighted:(BOOL)highlighted_
{
   BOOL oldValue = [self isHighlighted];
   if (highlighted_ != oldValue)
   {
      [super setHighlighted:highlighted_];
      // NSLog(@"highlighted: %d", highlighted_);
      [UIView beginAnimations:nil context:nil];
      [UIView setAnimationDuration:0.35f];
      [[self highlightView] setAlpha:(highlighted_?0.5f:0.0f)];
      [UIView commitAnimations];
   }
}

或许,一旦......预计会发生“TonUpInside”事件。

Thanks, MacTouch

问题回答

是的,这是一个共同的问题,可能是Pipe的 b。

但是,解决办法很简单,你可以确定你认为控制器类别的一个实例变数,并控制在要求你履行职务时变数。

类似于

your_method {
   if(control_var)
       control_var=NO;
   else {
       //APPLICATION LOGIC
      control_var=YES;
   }
}




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签