在ScrollView中缩放动画问题 - Ipad [英] zooming animation problem in ScrollView - Ipad

查看:123
本文介绍了在ScrollView中缩放动画问题 - Ipad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my app, I have a split screen in which the detail view is a scrollview. I have 5 tables which are subviews of my scrollview in which 3 table views are side by side on top and 2 table views are side by side on bottom

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

I have already implemented a way in which when I click any of the rows of any of the table in the scrollview, that view disappears and another view zooms into its position.

我写下面的内容中间表子视图中didSelectRowAtIndexPath中的代码,

I write the following code in the didSelectRowAtIndexPath in the middle table subview,

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是我需要放大到以前由特定表视图占用的视图的视图发生得正确。

popContents is the view I need to zoom into to the view previously occupied by that particular table view and that happens correctly.

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

However the problem that I am facing is that since there is another table subview in the side, if I increase the frame size to say 250 or so, the part of the zoomed in view gets hidden by the tableview on the side ( as its as if a part of the zoomed in view goes under the tableview on the side).

无论如何为了纠正这个问题,我的放大视图不会被其侧面的tableviews隐藏?

Is there anyway to correct this so that my zoomed in view would not get hidden by the tableviews on its sides?

我希望我已正确解释了我的问题......

I hope I have explained my problem correctly...

更新:

以下是我用于添加scrollview子视图的代码

Here is the code I am using for adding the subviews for the 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的代码......

say for example, I add the code for didSelectRowAtIndexPath in cViewController subview...

推荐答案

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

This is a guess since I would need to know how your table views are added to the scroll view, but the middle table view was probably added before the one on the side. Views are "stacked" in the order they're added with the last one on top. You'll need to get the scroll view to move the middle view to the front with this method

- (void)bringSubviewToFront:(UIView *)view

最好的方法是为表格视图创建协议并使滚动视图成为委托。该方法将是这样的

The best way to do that would be to create a protocol for the table views and make the scroll view the delegate. The method would be something like this

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

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

You would then call the delegate method before setting up the animation.

已编辑

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

After a little more thought I realized that the subviews have a reference to their superview so this bit of code should provide an idea on how to solve the problem. I created a test app which has a view controller which adds two sub views. The view controller header file is 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 with另一个简单的标题

The subview class is MoveableSubview with another simple header

#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];

行。

这篇关于在ScrollView中缩放动画问题 - Ipad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆