1

我在 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中写了一个按钮事件动作。当我点击按钮时,图像没有移动到按钮上。

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

4

2 回答 2

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];
}
于 2012-06-08T10:22:14.440 回答
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:)];    

}
}
于 2012-07-25T05:14:05.537 回答