动画开源库:HMGLTransitions (WXHL) 3D动画切换, 开门效果等
2013-08-18 17:00
197 查看
#import "RootViewController.h"
#import "Switch3DTransition.h"
#import "FlipTransition.h"
#import "RotateTransition.h"
#import "ClothTransition.h"
#import "DoorsTransition.h"
#import "ModalViewController.h"
@interface RootViewController()
@property (nonatomic, retain) HMGLTransition *transition;
@end
@implementation RootViewController
@synthesize view1;
@synthesize view2;
@synthesize transition;
#pragma mark -
#pragma mark UIViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
Switch3DTransition *t1 = [[[Switch3DTransition alloc] init] autorelease];
t1.transitionType = Switch3DTransitionLeft;
FlipTransition *t2 = [[[FlipTransition alloc] init] autorelease];
t2.transitionType = FlipTransitionRight;
transitionsArray = [[NSArray alloc] initWithObjects:
[[[Switch3DTransition alloc] init] autorelease],
t1,
[[[ClothTransition alloc] init] autorelease], [[[FlipTransition alloc] init] autorelease],
t2,
[[[RotateTransition alloc] init] autorelease],
[[[DoorsTransition alloc] init] autorelease],nil];
transitionsNamesArray = [[NSArray alloc] initWithObjects:
@"Switch 3D right",
@"Switch 3D left",
@"Cloth",
@"Flip left",
@"Flip right",
@"Rotate",
@"Doors",
nil];
self.transition = [transitionsArray objectAtIndex:0];
}
return self;
}
- (void)viewDidLoad {
// Creating singleton of transition manager here helps to reduce lag when showing first transition.
[HMGLTransitionManager sharedTransitionManager];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
#pragma mark -
#pragma mark Transitions
- (void)switchToView2 {
UIView *containerView = view1.superview;
[[HMGLTransitionManager sharedTransitionManager] setTransition:transition];
[[HMGLTransitionManager sharedTransitionManager] beginTransition:containerView];
// Here you can do whatever you want except changing position, size or transformation of container view, or removing it from view hierarchy.
view2.frame = view1.frame;
[view1 removeFromSuperview];
[containerView addSubview:view2];
[[HMGLTransitionManager sharedTransitionManager] commitTransition];
}
- (void)switchToView1 {
UIView *containerView = view2.superview;
// Set transition
[[HMGLTransitionManager sharedTransitionManager] setTransition:transition];
[[HMGLTransitionManager sharedTransitionManager] beginTransition:containerView];
// Here you can do whatever you want except changing position, size or transformation of container view, or removing it from view hierarchy.
view1.frame = view2.frame;
[view2 removeFromSuperview];
[containerView addSubview:view1];
// Commit transition
[[HMGLTransitionManager sharedTransitionManager] commitTransition];
}
#pragma mark -
#pragma mark ModalController delegate
- (void)modalControllerDidFinish:(ModalViewController *)modalController {
[[HMGLTransitionManager sharedTransitionManager] setTransition:transition];
[[HMGLTransitionManager sharedTransitionManager] dismissModalViewController:modalController];
}
#pragma mark -
#pragma mark Actions
- (IBAction)viewTransitionButtonPressed:(id)sender {
UIButton *button = (UIButton*)sender;
// view transition to view1 or view2 depending on actual view
if (button.superview == view1) {
[self switchToView2];
}
else {
[self switchToView1];
}
}
- (IBAction)modalPresentationButtonPressed:(id)sender {
[[HMGLTransitionManager sharedTransitionManager] setTransition:transition];
ModalViewController *newController;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
newController = [[ModalViewController alloc] initWithNibName:@"ModalViewController-iPad" bundle:nil];
}
else {
newController = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];
}
newController.delegate = self;
[[HMGLTransitionManager sharedTransitionManager] presentModalViewController:newController onViewController:self];
[newController release];
}
#pragma mark -
#pragma mark TableView delegate and data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [transitionsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if ([transitionsArray objectAtIndex:indexPath.row] == transition) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
selectedTransitionIdx = indexPath.row;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.textLabel.text = [transitionsNamesArray objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row != selectedTransitionIdx) {
self.transition = [transitionsArray objectAtIndex:indexPath.row];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, [NSIndexPath indexPathForRow:selectedTransitionIdx inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
}
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
}
#pragma mark -
#pragma mark Memory
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.view1 = nil;
self.view2 = nil;
}
- (void)dealloc {
[transitionsArray release];
[transition release];
[view1 release];
[view2 release];
[super dealloc];
}
@end
相关文章推荐
- 页面切换动画效果4 - 3D切换
- 页面切换动画效果5 - 3D+缩放同时进行
- 用CATransform3D实现3D效果和制作简单3D动画
- 使用animate()完成修改图片src切换图片的动画效果
- 3D可视化技术之Cult3D【实战动画效果小汽车】
- qml页面切换动画效果
- JQuery 淡出、 动画、显示/隐藏切换等效果
- Android开源动画效果
- Android 深入ViewPager补间动画,实现类京东商城首页广告Banner切换效果
- Android下fragment切换的动画效果
- DIV动态/动画切换效果
- ViewFilpper动画切换效果
- Android 深入ViewPager补间动画,实现类京东商城首页广告Banner切换效果
- iphone应用中的动画效果之loading效果和界面切换效果
- Android动画之3D翻转效果实现函数分析
- android轻量框架三__Activity动画切换效果
- 收集android上开源的酷炫的交互动画和视觉效果:Interactive-animation
- css实现3D动画效果
- activity切换无动画效果的实现
- [Android实例] ViewPager多页面滑动切换以及动画效果