使用tableview作为水平滚动和动画视图,并像文本框一样动画文本

时间:2012-10-17 10:30:40

标签: objective-c

//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;
}

使用上述方法,可以将表视图转换为水平滚动视图。您可以通过双击图像并在屏幕上移动图像来拖动图像视图。 如果您有任何疑问,请随意。

0 个答案:

没有答案