0

ボタンは ではなく、UIButtonのサブクラスですUIControl

ユーザーが my をタップするUIControlと、アルファを変更して、ユーザーが押されているという視覚的なフィードバックを得ることができるようにします。その後、リリース時に再度変更します

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

アルファ使用を変更するには:mask.alpha = 0.0f;

これを行うにはIBActions:
ボタンが押されたときに動作するには:

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

ボタンを元のアルファに戻すには:

-(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

ボタンを元のアルファに戻すには:

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

これは、xib/ストーリーボード インターフェイスがあるかどうかに関係なく機能します。

于 2012-10-01T20:23:34.220 に答える