0

按钮不是 a UIButton,它是UIControl

当用户点击 myUIControl时,我想更改 alpha 以便用户有一些视觉反馈,它被按下。然后释放时再次更改

UIImageView *mask =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 58, 58)];
mask.image =[UIImage imageNamed:@"centerButton.png"];
mask.center = self.center;
mask.center = CGPointMake(mask.center.x, mask.center.y+3);
[self addSubview:mask];

中心按钮是使用rayWenderlich.com的教程创建的,用于学习创建自定义控件。

我被困住了。我不知道如何引用中心图像。

这是我的 .h 课程

@interface OOTRotaryWheel : UIControl


@property (weak) id <OOTRotaryProtocol> delegate;
@property (nonatomic, strong) UIView *container;
@property int numberOfSections;
@property CGAffineTransform startTransform;
@property (nonatomic, strong) NSMutableArray *sectors;
@property int currentSector;
@property (nonatomic, retain) UIImageView *mask;

- (id) initWithFrame:(CGRect)frame andDelegate:(id)del withSections:(int)sectionsNumber;
- (void)rotate;
- (void) buildSectorsEven;
- (void) buildSectorsOdd;

@end

那么如何检测 UIImageView 上的触地并触地呢?让它更像一个按钮(所以当我可以加载另一个 xib 或其他东西时)

4

1 回答 1

1

要更改 alpha 使用:mask.alpha = 0.0f;

要做到这一点IBActions
按下按钮时采取行动:

-(IBAction)buttonPressedDown{
      mask.alpha = 0.5f;
}//Connect this IBAction to touchDown

要将按钮更改回原来的 Alpha:

-(IBAction)buttonUpInsideAndOutside{
      mask.alpha = 1.0f;
}//Connect this IBAction to touchUpInside and touchUpOutside

要做到这一点UITouches
按下按钮时采取行动:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
      UITouch*touch = [touches anyObject];
      if(touch.view==mask)
            mask.alpha = 0.5f;
}//Will only work if the IBOutlet is connected

要将按钮更改回原来的 Alpha:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
      mask.alpha = 1.0f;
}//Will only work if the IBOutlet is connected

无论您是否有 xib/storyboard 界面,这都会起作用。

于 2012-10-01T20:23:34.220 回答