当我点击按钮时图像下降时如何移动到下一个屏幕?

时间:2012-06-08 04:06:04

标签: ios image button tap

我在viewDidLoad方法中编写了动画概念,我写道:

    scaleFactor=2;
    angle=180;
    CGRect frame = CGRectMake(10,10,45,45);
    UIView *box;
    box=[[UIView alloc] initWithFrame:frame];
    box.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"images673.png"];
    [self.view addSubView:box];

//此代码用于屏幕中对象的触摸事件 //对于对象移动,我编写了如下所示的方法:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
        {
        UITouch *touch=[touches anyObject];
        CGPoint location=[touch locationInView:self.view];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDelegate:self];
        [UICiew setAnimationDuration:1];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        box.center=location;
        [UIView commitAnimations];
        }

//然后,现在我写了一个按钮,它必须导航到另一个类文件//我写的一般导航原理

-(IBAction)settings:(id)sender
{
aScreen *abc=[[aScreen alloc]init];
[self.navigationController pushViewController:abc animated:YES];
[abc release];
}

现在对象正在移动我点击屏幕的位置,但是当我点击按钮时,图像没有放在按钮的顶部。怎么办。请帮助我。我拍了一张图像然后我做了一些动画,让它移动到我在屏幕上点击的位置。但与此同时,我拿了一个按钮,我在viewcontroller中编写了一个按钮事件动作。当我点击按钮时,图像没有移动到按钮上。

我想要做的是,如果我点击按钮,图像必须放在按钮上,它应该显示下一个视图控制器。任何人都可以帮我这样做吗?当我点击按钮时,如何在图像落入时移动到下一个屏幕?

2 个答案:

答案 0 :(得分:0)

我不确定在没有看到你的代码的情况下我完全理解这个问题但是你不能做这样的事情吗?

-(ibaction)buttonevent:(id)sender{
cgrect frame = image.frame;
frame.origin.x = button.frame.x;
frame.origin.y = button.frame.y;
image.frame = frame;
image.alpha = 0;

[self pushviewcontroller:newViewcontroller animated:yes];
}

答案 1 :(得分:0)

嗨试试这个代码我已经检查过了。当你检查按钮并且拖动的图像相交时,这对我有用,然后激活它移动到下一个屏幕的方法

// Handles the continuation of a touch.
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{  
//NSLog(@"touchesMoved");
UITouch *touch = [touches anyObject];
if ([touch view] == mKey) {

    NSUInteger touchCount = 0;

    // Enumerates through all touch objects
    for (UITouch *touch in touches) {
        // Send to the dispatch method, which will make sure the appropriate subview is acted upon
        [self dispatchTouchEvent:[touch view] toPosition:[touch locationInView:self.view]];
        touchCount++;
    }

}



}

// Checks to see which view, or views, the point is in and then sets the center of each moved view to the new postion.
// If views are directly on top of each other, they move together.
-(void)dispatchTouchEvent:(UIView *)theView toPosition:(CGPoint)position
{

// Check to see which view, or views,  the point is in and then move to that position.

if (CGRectContainsPoint([mKey frame], position)) 
{
     NSLog(@"touchesMoved");
    mKey.center = position;

}


if(CGRectIntersectsRect([mKey frame], [inVisible frame]) && k==0)
{
    self.view.userInteractionEnabled=NO;
    NSLog(@"thirdPiew frame");

    [inVisible setHighlighted:YES];
    [inVisible setShowsTouchWhenHighlighted:YES];
    k=1;
    [self performSelector:@selector(modalPresentationButtonPressed:)];    

}
}