0

在我的UIScrollView中我有一个视图。在这个视图中有几个图像。我想将图像从我的滚动条(和视图)拖出到主视图。然而,将图像放在滚动条和视图的前面会让我疯狂。在滚动视图中使用手势(通过手势将内容移出滚动视图)

这一块我的代码:

- (void)viewDidLoad{ 

    //scroller properties 
    scroller.contentSize = CGSizeMake(1300, 130); 
    scroller.scrollEnabled = YES; 
    scroller.directionalLockEnabled =YES; 
    scroller.frame = CGRectMake(0, 874, 768, 130); 
    [scroller setDelegate:self]; 

    UIView *contentContainer = [[UIView alloc] init]; 

    [scroller addSubview:contentContainer]; 
    [scroller addSubview:image1]; 
    [scroller bringSubviewToFront:image1]; 
    [speler1 release]; 

    UILongPressGestureRecognizer *longPress1 = 
    [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)]; 
    [image1 addGestureRecognizer:longPress1]; 
    [longPress1 release]; 

    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)]; 
    [panRecognizer setMinimumNumberOfTouches:1]; 
    [panRecognizer setMaximumNumberOfTouches:1]; 
    [panRecognizer setDelegate:self]; 
    [image1 addGestureRecognizer:panRecognizer]; 


} 

-(void)longPressed:(UILongPressGestureRecognizer *)sender { 

    [[self.view superview] bringSubviewToFront:image1]; 

} 

-(void)move:(id)sender { 

    //move the image 

} 

我想用LongPressGestureRecognizer带来的图像的意见面前。 PanGestureRecognizer负责移动图像。拖动仅在滚动视图内工作。任何人都知道如何将我的图像放在视图前面?

帮助感激

+0

下一次你应该选择更好的标签。这将大大提高您的问题的可见性。如果没有人发现你的问题,没人会回答。 – 2011-03-24 10:21:07

+0

谢谢我会保持它提醒! – BarryK88 2011-03-24 10:27:25

回答

0

我成功与把图像从卷轴到主视图。看到我的代码如下。

- (void)viewDidLoad{ 

    //scroller properties 
    scroller.contentSize = CGSizeMake(1300, 130); 
    scroller.scrollEnabled = YES; 
    scroller.directionalLockEnabled =YES; 
    scroller.frame = CGRectMake(0, 874, 768, 130); 
    [scroller setDelegate:self]; 
    [scroller addSubview:image1]; 

    [image1 release]; 

    UILongPressGestureRecognizer *longPress1 = 
    [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)]; 
    [image1 addGestureRecognizer:longPress1]; 
    [longPress1 release]; 

    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)]; 
    [panRecognizer setMinimumNumberOfTouches:2]; 
    [panRecognizer setMaximumNumberOfTouches:2]; 
    [panRecognizer setDelegate:self]; 
    [image1 addGestureRecognizer:panRecognizer]; 


} 

-(void)longPressed:(UILongPressGestureRecognizer *)sender { 

    CGPoint location = [sender locationInView:self.view]; 
    [self.view addSubview:image1]; 
    image1.center = location; 
} 

-(void)move:(id)sender { 

    //move the image 
} 

现在我希望能够将我的图像放回我的滚动视图。我试图通过touchesended和doubletap来实现这一点。图像将被放置到它的原点。但是它不会回滚到滚动条内。这是一个touchedended方法。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    [super touchesEnded:touches withEvent:event]; 

    UITouch *touch = [touches anyObject]; 

    if ([touch tapCount] == 2) { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationBeginsFromCurrentState:YES]; 
     [UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
     [UIView setAnimationDuration:0.20]; 
     [UIView commitAnimations]; 

     image1.transform = CGAffineTransformIdentity; 
     image1.center = CGPointMake(20, 20); 

     [self.view sendSubviewToBack:image1]; 

     return; 
    } 
} 

希望有人能指出我朝着正确的方向把图像回我的卷轴里的它是从哪里来的同一位置。

在此先感谢!