//To Drag the image View on the iphone screen
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
point0 = [touch locationInView:self.view];
if ([touch tapCount] == 2) {
dropDownBool = NO;
pushUpBool = NO;
self.imageView.alpha = 0.4;
doublePressed = YES;
}
if(doublePressed)
{
point0 = [touch locationInView:self.view];
if (CGRectContainsPoint([self.imageView frame], [touch locationInView:[touch view]]))
{
self.imageView.center = [touch locationInView:nil];
}
}
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
point0 = [touch locationInView:self.imageView];
if(doublePressed)
{
UITouch *touch = [[event allTouches] anyObject];
point0 = [touch locationInView:self.imageView];
//animating the view...
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform =CGAffineTransformTranslate(CGAffineTransformIdentity,0.0f, 0.0f);
self.imageView.transform = transform;
[UIView commitAnimations];
doublePressed = NO;
self.imageView.alpha = 1.0;
}
}
// To drop down a view as you swipe on top of the screen
-(void)handleSwipeGesture:(UISwipeGestureRecognizer *) sender
{
//Gesture detect - swipe up/down , can be recognized direction
if(sender.direction == UISwipeGestureRecognizerDirectionUp)
{
pushUpBool = YES;
}
else
if(sender.direction == UISwipeGestureRecognizerDirectionDown)
{
dropDownBool = YES;
}
if(dropDownBool && (point0.y < 80.0f))
{
NSLog(@"%f",point0.y);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.dropDownView.center = CGPointMake(originalCenter.x,30.0 );
self.dropDownView.alpha = 0.8;
dropDownBool = NO;
}
if(pushUpBool && (point0.y < 80.0f))
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
pushUpBool = NO;
self.dropDownView.center = originalCenter;
self.dropDownView.alpha = 0.0;
}
}
// animates from left to right like Marqee...
-(void) scrollLeft
{
CABasicAnimation *scrollText;
scrollText=[CABasicAnimation animationWithKeyPath:@"position.x"];
scrollText.duration = 6.0;
scrollText.repeatCount = 10000;
scrollText.autoreverses = NO;
scrollText.fromValue = [NSNumber numberWithFloat:500];
scrollText.toValue = [NSNumber numberWithFloat:-120.0];
[[self.detailView layer] addAnimation:scrollText forKey:@"scrollTextKey"];
}
// Making the table View scroll horizontally place this code in viewDidLoad.
CGAffineTransform transform = CGAffineTransformMakeRotation(-1.5707963);
self.horizontalTableView.transform = transform;
// now in tableview method transform the cell back.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
CGAffineTransform transform = CGAffineTransformMakeRotation(1.5707963);
cell.transform = transform;
}
上記の方法を使用すると、テーブルビューを水平スクロールビューのように変換できます。画像をダブルクリックして画面上で移動すると、画像ビューをドラッグできます。ご不明な点がございましたらお気軽にお問い合わせください。