OC利用delegate实现霓虹灯效果
来源:互联网 发布:专业淘宝刷销量 编辑:程序博客网 时间:2024/04/28 12:10
#import <UIKit/UIKit.h>
@protocol colorChangeDelegate <NSObject>
- (void)colorChange;
@end
@interface NewView : UIView
@property (nonatomic, retain)id<colorChangeDelegate>delegate;
@end
#import "NewView.h"
@implementation NewView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
for (int i = 0; i < 4; i++) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width * (4 - i) / 5, self.frame.size.height * (4 - i) / 5)];
view.center = self.center;
view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1];
view.tag = 4 - i;
[self addSubview:view];
[view release];
}
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.delegate colorChange];
}
@end
#import <UIKit/UIKit.h>
#import "NewView.h"
@interface MainViewController : UIViewController<colorChangeDelegate>
@property (nonatomic, retain)NSTimer *timer;
@property (nonatomic, assign)BOOL click;
@property (nonatomic, assign)NSInteger style;
@end
#import "MainViewController.h"
#import "NewView.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (void)viewDidLoad {
[super viewDidLoad];
_style = 5;
self.view.backgroundColor = [UIColor whiteColor];
NewView *view = [[NewView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width)];
view.backgroundColor = [UIColor blackColor];
view.tag = 5;
view.delegate = self;
[self.view addSubview:view];
[view release];
// Do any additional setup after loading the view.
}
-(void)colorChange {
if (!_click) {
_timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(colorDidChange) userInfo:nil repeats:YES];
_click = !_click;
}
else {
_click = !_click;
[_timer invalidate];
}
}
- (void)colorDidChange {
self.view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:arc4random() % 256 / 255.0];
[self.view viewWithTag:_style].backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1];
_style--;
if (_style == 1) {
_style = 5;
}
}
@end
- OC利用delegate实现霓虹灯效果
- IOS 霓虹灯效果(oc)
- js实现霓虹灯效果
- 实现霓虹灯闪烁效果(UI)
- 使用FrameLayout实现霓虹灯效果
- 利用UIView做出霓虹灯的效果
- 霓虹灯效果
- Android帧布局实现霓虹灯的效果
- 帧布局FrameLayout实现霓虹灯效果
- Android:帧布局实现霓虹灯的效果
- 【Android】使用FrameLayout布局实现霓虹灯效果
- 霓虹灯效果(用TextView实现)
- Android之霓虹灯实现小效果
- FrameLayout(帧布局)实现闪烁霓虹灯效果
- 利用UIBezierPath实现的橡皮筋动画效果(OC版)
- 使用CSS3 and jQuery 实现霓虹灯闪烁效果
- android布局之帧布局-----霓虹灯效果实现
- android学习笔记6:使用Framelayout实现霓虹灯效果
- SEAndroid语法介绍
- OC第一天
- OC实现简单的点名器
- Java关键字final
- iOS应用内支付(IAP)的那些坑
- OC利用delegate实现霓虹灯效果
- Object-C系列<Xcode中ARC 下两种释放对象的方法>
- Objective-C 二维数组详解
- Java编码问题
- UISegmentedControl详解
- should not include d3dtypes.h when compiling for DX8 or newer interfaces
- 下拉菜单 spinner ,popupwindow, 自定义popupwindow总结
- 在linux文本中打开出现乱码问题
- 适合初学者理解的A*(A星)算法(转)