在ScrollView中缩放动画问题 - Ipad

时间:2011-04-14 19:43:11

标签: ipad uiscrollview core-animation zoom uisplitviewcontroller

在我的应用中,我有一个分屏,其中详细视图是一个滚动视图。我有5张表,这是我的滚动视图的子视图,其中3个表视图并排在顶部,2个表视图在底部并排

我已经实现了一种方法,当我点击滚动视图中任何一个表的任何行时,该视图消失,另一个视图缩放到其位置。

我在中间表子视图的didSelectRowAtIndexPath中编写以下代码,

CGFloat xpos = self.view.frame.origin.x;
    CGFloat ypos = self.view.frame.origin.y;
    self.view.frame = CGRectMake(xpos+100,ypos+150,5,5);
    [UIView beginAnimations:@"Zoom" context:NULL];
    [UIView setAnimationDuration:2];
    self.view.frame = CGRectMake(xpos,ypos,220,310);
    [UIView commitAnimations];
    [self.view addSubview:popContents.view];

popContents是我需要放大到以前由特定表视图占用的视图并且正确发生的视图。

然而,我面临的问题是,由于侧面有另一个表子视图,如果我将帧大小增加到250左右,则放大视图的部分会被侧视图中的表视图隐藏(就好像放大视图的一部分位于侧面的桌面视图下一样。)

无论如何都要纠正这个问题,这样我的放大视图就不会被侧面的桌面视图隐藏起来了吗?

我希望我能正确解释我的问题......

更新:

以下是我用于添加scrollview

的子视图的代码
// Scroll view
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30, 1000, 740)];
scrollView.contentSize = CGSizeMake(1000, 700);
scrollView.delegate = self;
scrollView.scrollEnabled = YES;
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
[self.view addSubview:scrollView];


aView = [[aViewController alloc] initWithNibName:@"aViewController" bundle:nil];
aView.view.frame = CGRectMake(10, 25, 220, 310);
[aView loadList:objPatients];
[scrollView addSubview:aView.view];

bView = [[bViewController alloc] initWithNibName:@"bViewController" bundle:nil];
bView.view.frame = CGRectMake(10, 350, 220, 310);
[bView loadList:objPatients];
[scrollView addSubview:bView.view];

cView = [[cViewController alloc] initWithNibName:@"cViewController" bundle:nil];
cView.view.frame = CGRectMake(240, 25, 220, 310);
[cView loadList:objPatients];
[scrollView addSubview:cView.view];

dView = [[dViewController alloc] initWithNibName:@"dViewController" bundle:nil];
enView.view.frame = CGRectMake(240, 350, 220, 310);
[enView loadList:objPatients];
[scrollView addSubview:dView.view];

eView = [[eViewController alloc] initWithNibName:@"eViewController" bundle:nil];
eView.view.frame = CGRectMake(470, 25, 220, 310);
[eView loadList:objPatients];
[scrollView addSubview:eView.view];

例如,我在cViewController子视图中添加了didSelectRowAtIndexPath的代码...

1 个答案:

答案 0 :(得分:2)

这是一个猜测,因为我需要知道如何将表视图添加到滚动视图,但中间表视图可能在侧面之前添加。视图按照它们添加的顺序“堆叠”,最后一个视图位于顶部。您需要使用此方法获取滚动视图以将中间视图移动到前面

- (void)bringSubviewToFront:(UIView *)view

执行此操作的最佳方法是为表视图创建协议,并使滚动视图成为委托。该方法将是这样的

- (void) moveAViewToFront: (MyTableView *) aTableView
{
    [self.view bringSubviewToFront: aTableView.view];
}

然后在设置动画之前调用委托方法。

<强>被修改

经过一番思考后,我意识到子视图引用了他们的超级视图,所以这段代码应该提供一个如何解决问题的想法。我创建了一个测试应用程序,它有一个视图控制器,可以添加两个子视图视图控制器头文件是MoveSubviewViewController.h

#import <UIKit/UIKit.h>

@interface MoveSubviewViewController : UIViewController
{
}

@end

它的实现是

#import "MoveSubviewViewController.h"
#import "MoveableSubview.h"

@implementation MoveSubviewViewController

    - (void)viewDidLoad
    {
        [super viewDidLoad];

        // Create two overlapping subviews. The blue subview will start at the top of
        //  the frame and extend down two thirds of the frame.
        CGRect superviewFrame = self.view.frame;
        CGRect view1Frame = CGRectMake( superviewFrame.origin.x, superviewFrame.origin.y,
                                       superviewFrame.size.width, superviewFrame.size.height * 2 / 3);
        MoveableSubview *view1 = [[MoveableSubview alloc] initWithFrame: view1Frame];
        view1.backgroundColor = [UIColor blueColor];
        [self.view addSubview: view1];
        [view1 release];

        // The green subview will start one third of the way down the frame and
        //  extend all the to the bottom.
        CGRect view2Frame = CGRectMake( superviewFrame.origin.x,
                                       superviewFrame.origin.y + superviewFrame.size.height / 3,
                                       superviewFrame.size.width, superviewFrame.size.height * 2 / 3);
        MoveableSubview *view2 = [[MoveableSubview alloc] initWithFrame: view2Frame];
        view2.backgroundColor = [UIColor greenColor];
        [self.view addSubview: view2];
        [view2 release];
    }

    @end

子视图类是MoveableSubview,带有另一个简单的标题

#import <UIKit/UIKit.h>

@interface MoveableSubview : UIView
{
}
@end

和实施

#import "MoveableSubview.h"

@implementation MoveableSubview

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    // Move this view to the front in the superview.
    [self.superview bringSubviewToFront: self];
}

@end

要做的是添加

[self.superview bringSubviewToFront: self];
在设置动画之前

行。