首页 > 代码库 > 七彩霓虹灯可以实现两种效果
七彩霓虹灯可以实现两种效果
// MHTAppDelegate.h
// HomeworkNeonLamp
// Copyright (c) 2014年 Summer. All rights reserved.
#import<UIKit/UIKit.h>
@interface MHTAppDelegate :UIResponder <UIApplicationDelegate>
@property (retain,nonatomic) UIWindow *window;
@end
// MHTAppDelegate.m
// HomeworkNeonLamp
// Copyright (c) 2014年 Summer. All rights reserved.
#import"MHTAppDelegate.h"
@interfaceMHTAppDelegate()
{
UIView *_containerView;
UIView *_toOutsideView;
UIView *_toInsideView;
UIView *_otherView;
UIView *_view;
NSArray *_color;
}
@end
@implementation MHTAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];
// Override point for customization after application launch.
_color = [NSArrayarrayWithObjects:[UIColorredColor], [UIColororangeColor], [UIColoryellowColor], [UIColorgreenColor], [UIColorblueColor], [UIColorcyanColor], [UIColorpurpleColor], nil];
//创建背景画布
_containerView = [[UIViewalloc] initWithFrame:CGRectMake(0,0, 320,568)];
_containerView.backgroundColor = [UIColorclearColor];
[self.windowaddSubview:_containerView];
[_containerViewrelease];
_toOutsideView = [[UIViewalloc] initWithFrame:CGRectMake(0,0, 320,568)];
_toOutsideView.backgroundColor = [UIColorclearColor];
[_containerViewaddSubview:_toOutsideView];
_toOutsideView.tag =100;
[_toOutsideViewrelease];
_toInsideView = [[UIViewalloc] initWithFrame:CGRectMake(0,0, 320,568)];
_toInsideView.backgroundColor = [UIColorclearColor];
[_containerViewaddSubview:_toInsideView];
_toInsideView.tag =101;
[_toInsideViewrelease];
[selftoIN];
[selftoOUT];
[selfbut];
[selfLine];
[NSTimerscheduledTimerWithTimeInterval:0.1target:selfselector:@selector(click)userInfo:nilrepeats:YES];
self.window.backgroundColor = [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
return YES;
}
- (void)toIN
{
for (int i = 0; i < 7; i++) {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10 +20 * i, 80 + 34 +30 * i, 300 - (0 +20 * i) * 2, 500 - (80 +30 * i) * 2)];
view.backgroundColor = [_colorobjectAtIndex:i];
[_toInsideViewaddSubview:view];
[viewrelease];
view.tag =200 + i;
}
NSLog(@"%@", [_toInsideViewsubviews]);
}
- (void)toOUT
{
for (int i = 0; i < 7; i++) {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10 +20 * i, 80 + 34 +30 * i, 300 - (0 +20 * i) * 2, 500 - (80 +30 * i) * 2)];
view.backgroundColor = [_colorobjectAtIndex:i];
[_toOutsideViewaddSubview:view];
[viewrelease];
view.tag =200 + i;
}
NSLog(@"%@", [_toOutsideViewsubviews]);
}
- (void)but
{
UIButton *but = [UIButtonbuttonWithType:UIButtonTypeCustom];
but.frame =CGRectMake(10, 30,300, 30);
[butsetTitle:@"切 换 效 果" forState:UIControlStateNormal];
but.titleLabel.font = [UIFontfontWithName:@"EuphemiaUCAS" size:20 ];
[butsetTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
but.backgroundColor = [UIColoryellowColor];
but.layer.cornerRadius =5;
but.layer.borderWidth =1;
but.layer.borderColor = [[UIColorblueColor] CGColor];
[butaddTarget:selfaction:@selector(butClick:)forControlEvents:UIControlEventTouchUpInside];
[_containerViewaddSubview:but];
but.tag =104;
}
- (void)butClick:(UIButton *)but
{
[_containerViewexchangeSubviewAtIndex:0withSubviewAtIndex:1];
}
- (void)click
{
//由里向外
UIView *temp = [[UIView alloc]init];
temp.backgroundColor = [_toOutsideViewviewWithTag:200].backgroundColor;
for (int i = 200; i < 206; i++) {
[_toOutsideViewviewWithTag:i].backgroundColor = [_toOutsideViewviewWithTag: i + 1].backgroundColor;
}
[_toOutsideViewviewWithTag:206].backgroundColor =temp.backgroundColor;
[temp release];
//由外向里
UIView *temp1 = [[UIView alloc]init];
temp1.backgroundColor = [_toInsideViewviewWithTag:206].backgroundColor;
for (int i = 206; i > 200; i--) {
[_toInsideViewviewWithTag:i].backgroundColor = [_toInsideViewviewWithTag:i - 1].backgroundColor;
}
[_toInsideViewviewWithTag:200].backgroundColor = temp1.backgroundColor;
[temp1 release];
}
- (void)Line
{
//copyrightLine(版权)
UILabel *copyrightLine = [[UILabel alloc] initWithFrame:CGRectMake(20,520, 280, 2)];
copyrightLine.backgroundColor = [UIColorgrayColor];
copyrightLine.layer.cornerRadius =5;
copyrightLine.layer.masksToBounds =YES;
[_containerViewaddSubview:copyrightLine];
[copyrightLinerelease];
UILabel *copyrightLable = [[UILabel alloc] initWithFrame:CGRectMake(20,480, 280, 20)];
copyrightLable.textAlignment =NSTextAlignmentCenter;
copyrightLable.text =@"Copyright ? 2014 summer";
copyrightLable.font = [UIFontfontWithName:@"AppleSDGothicNeo-Thin"size:12];
[_containerViewaddSubview:copyrightLable];
[copyrightLablerelease];
UILabel *copyrightLable1 = [[UILabel alloc] initWithFrame:CGRectMake(20,500, 280, 20)];
copyrightLable1.textAlignment =NSTextAlignmentCenter;
copyrightLable1.text =@"summer2014mht@sina.com";
copyrightLable1.font = [UIFontfontWithName:@"AppleSDGothicNeo-Thin"size:12];
[_containerViewaddSubview:copyrightLable1];
[copyrightLable1release];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
- (void)dealloc
{
[_windowrelease];
[superdealloc];
}
@end
七彩霓虹灯可以实现两种效果