Permalink
Browse files

Adding gestures to gawk view!

  • Loading branch information...
1 parent c7fd9bd commit c68d8cbc756eb1dff39f889d57afa5ee48669a01 @tomgco committed Jun 7, 2011
View
@@ -7,7 +7,6 @@
//
#import "AlbumVideoViewController.h"
-#import <MediaPlayer/MediaPlayer.h>
@implementation AlbumVideoViewController
@@ -56,14 +55,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}
- (void)showVideo:(NSURL *)gawkUrl {
- MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: gawkUrl];
- //player.moviePlayer.repeatMode = MPMovieRepeatModeOne;
- //[self presentMoviePlayerViewControllerAnimated:player];
- player.repeatMode = MPMovieRepeatModeOne;
- player.movieSourceType = MPMovieSourceTypeFile;
- player.controlStyle = MPMovieControlStyleNone;
- [player.view setFrame: self.view.bounds]; // player's frame must match parent's
- [video addSubview: player.view];
+
}
@end
@@ -8,18 +8,21 @@
#import <UIKit/UIKit.h>
#import "ApplicationCell.h"
-#import "AlbumVideoViewController.h"
+#import <MediaPlayer/MediaPlayer.h>
@interface AlbumViewController : UITableViewController {
NSArray *tableDataSource;
IBOutlet UIView *videoPlayer;
IBOutlet UIView *videoView;
ApplicationCell *tmpCell;
- AlbumVideoViewController *albumVideoView;
+ MPMoviePlayerController *player;
+ NSUInteger videoId;
}
@property (nonatomic, retain) NSArray *tableDataSource;
-@property (nonatomic, retain) AlbumVideoViewController *albumVideoView;
@property (nonatomic, assign) IBOutlet ApplicationCell *tmpCell;
+@property (nonatomic, retain) MPMoviePlayerController *player;
+
+- (IBAction)backToList;
@end
@@ -9,14 +9,15 @@
#import "AlbumViewController.h"
#import "GawkAppDelegate.h"
#import <QuartzCore/QuartzCore.h>
+#import <MediaPlayer/MediaPlayer.h>
#define DARK_BACKGROUND [UIColor colorWithRed:151.0/255.0 green:152.0/255.0 blue:155.0/255.0 alpha:1.0]
#define LIGHT_BACKGROUND [UIColor colorWithRed:172.0/255.0 green:173.0/255.0 blue:175.0/255.0 alpha:1.0]
@implementation AlbumViewController
-@synthesize tableDataSource, tmpCell, albumVideoView;
+@synthesize tableDataSource, tmpCell, player;
- (id)initWithStyle:(UITableViewStyle)style
{
@@ -29,9 +30,7 @@ - (id)initWithStyle:(UITableViewStyle)style
- (void)dealloc
{
- [tableDataSource release];
- [albumVideoView release];
- [super dealloc];
+ [tableDataSource release]; [super dealloc];
}
- (void)didReceiveMemoryWarning
@@ -57,7 +56,64 @@ - (void)viewDidLoad
self.tableView.rowHeight = 73.0;
self.tableView.backgroundColor = DARK_BACKGROUND;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- albumVideoView = [[AlbumVideoViewController alloc] initWithNibName:@"AlbumVideoViewController" bundle:nil];
+ UISwipeGestureRecognizer *gestures;
+ gestures = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:)];
+ [gestures setDirection:UISwipeGestureRecognizerDirectionRight];
+ [videoPlayer addGestureRecognizer:gestures];
+ [gestures release];
+
+ gestures = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft:)];
+ [gestures setDirection:UISwipeGestureRecognizerDirectionLeft];
+ [videoPlayer addGestureRecognizer:gestures];
+ [gestures release];
+}
+
+-(void)handleSwipeRight:(UISwipeGestureRecognizer *)recognizer {
+ NSLog(@"Swipe right received.");
+ NSDictionary *cellData = [self.tableDataSource objectAtIndex:videoId];
+ NSLog(@"%d", videoId);
+ NSURL *gawkPath = [[[NSURL alloc] initWithString:[cellData objectForKey:@"GawkUrl"]] autorelease];
+
+ CATransition *animation = [CATransition animation];
+ [animation setDuration:0.4];
+ [animation setType:kCATransitionPush];
+ [animation setSubtype:kCATransitionFromLeft];
+ [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
+ [videoPlayer addSubview:videoView];
+ [self.tableView.superview addSubview:videoPlayer];
+ [[self.tableView.superview layer] addAnimation:animation forKey:@"SwipeToViewRight"];
+ player = [[MPMoviePlayerController alloc] initWithContentURL: gawkPath];
+
+ player.repeatMode = MPMovieRepeatModeOne;
+ player.movieSourceType = MPMovieSourceTypeFile;
+ player.controlStyle = MPMovieControlStyleNone;
+ [player.view setFrame: videoView.bounds]; // player's frame must match parent's
+ [videoView addSubview: player.view];
+ videoId = videoId == 0 ? [self.tableDataSource count] - 1 : videoId - 1;
+}
+
+-(void)handleSwipeLeft:(UISwipeGestureRecognizer *)recognizer {
+ NSLog(@"Swipe left received.");
+ NSLog(@"%d", videoId);
+ NSDictionary *cellData = [self.tableDataSource objectAtIndex:videoId];
+ NSURL *gawkPath = [[[NSURL alloc] initWithString:[cellData objectForKey:@"GawkUrl"]] autorelease];
+
+ CATransition *animation = [CATransition animation];
+ [animation setDuration:0.4];
+ [animation setType:kCATransitionPush];
+ [animation setSubtype:kCATransitionFromRight];
+ [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
+ [videoPlayer addSubview:videoView];
+ [self.tableView.superview addSubview:videoPlayer];
+ [[self.tableView.superview layer] addAnimation:animation forKey:@"SwipeToViewLeft"];
+ player = [[MPMoviePlayerController alloc] initWithContentURL: gawkPath];
+
+ player.repeatMode = MPMovieRepeatModeOne;
+ player.movieSourceType = MPMovieSourceTypeFile;
+ player.controlStyle = MPMovieControlStyleNone;
+ [player.view setFrame: videoView.bounds]; // player's frame must match parent's
+ [videoView addSubview: player.view];
+ videoId = videoId == ([self.tableDataSource count] - 1) ? 0 : videoId + 1;
}
- (void)viewDidUnload
@@ -136,6 +192,8 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)ce
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
+ videoId = indexPath.row;
+
NSDictionary *cellData = [self.tableDataSource objectAtIndex:indexPath.row];
NSURL *gawkPath = [[[NSURL alloc] initWithString:[cellData objectForKey:@"GawkUrl"]] autorelease];
// [player play];
@@ -144,9 +202,17 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
- [self.tableView.superview addSubview:albumVideoView.view];
+ [self.tableView.superview addSubview:videoPlayer];
[[self.tableView.superview layer] addAnimation:animation forKey:@"SwitchToView1"];
- [albumVideoView showVideo:gawkPath];
+ player = [[MPMoviePlayerController alloc] initWithContentURL: gawkPath];
+ //player.moviePlayer.repeatMode = MPMovieRepeatModeOne;
+ //[self presentMoviePlayerViewControllerAnimated:player];
+ player.repeatMode = MPMovieRepeatModeOne;
+ player.movieSourceType = MPMovieSourceTypeFile;
+ player.controlStyle = MPMovieControlStyleNone;
+ [player.view setFrame: videoView.bounds]; // player's frame must match parent's
+ [videoPlayer addSubview:videoView];
+ [videoView addSubview: player.view];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
@@ -168,4 +234,19 @@ - (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSInd
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView reloadData];
}
+
+- (IBAction) backToList {
+ CATransition *animation = [CATransition animation];
+ [animation setDuration:0.5];
+ [animation setType:kCATransitionPush];
+ [animation setSubtype:kCATransitionFromLeft];
+ [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
+ [videoView removeFromSuperview];
+ [videoPlayer removeFromSuperview];
+ [self.tableView.superview addSubview:self.tableView];
+ [player.view removeFromSuperview];
+ [player release];
+ [[self.tableView.superview layer] addAnimation:animation forKey:@"SwitchBackToView0"];
+}
+
@end
Oops, something went wrong.

0 comments on commit c68d8cb

Please sign in to comment.