打地鼠想必大家小时候都玩过,下面我们就通过多线程以及代理传值实现一个打地鼠游戏。
首先我们需要一个地鼠类。地鼠类中,需要用到代理。如果有同学对于代理还不够清楚的话,请参考微博:
http://blog.youkuaiyun.com/lee727n/article/details/70833160
地鼠类继承uibutton,定义协议,以及协议方法 .h中
@protocol MouseDelegate <NSObject>
- (void)successAction;
- (void)failAction;
@end
@interface Mouse : UIButton
@property (nonatomic, weak)id<MouseDelegate> delegate;
@end
. m 中 重写frame初始化方法
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor<