UIScrollView 中的 UIToolbar 修复了 UIViewController 作为子视图滚动的问题

发布于 2024-08-20 12:08:37 字数 1240 浏览 7 评论 0原文

我遇到了一个大问题,我不知道如何解决...

我的 UIToolbar 应该在屏幕底部修复,但在整个屏幕上显示缩放。

就我而言,我有:

UIViewController

一个带有 UIScrollView 滚动图像的

。所以我需要屏幕底部的工具栏,但它取代了图像滚动并占据了整个屏幕。当我从 iphone Xcode 的 V2 移动到 V3 时发生这种情况..在它显示正常之前...

我将简要解释一下我如何初始化这些东西: 在h文件中 UIScrollView *myScroll; 在我的 .M 文件中 UIToolbar *工具栏;

然后在 (void)viewDidLoad {

toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleDefault;

toolbar.frame = CGRectMake(0, 410, 320, 50);
------------------------

myScroll.contentSize = CGSizeMake(myImage.frame.size.width, myImage.frame.size.height);

myScroll.maximumZoomScale = 4.0;
myScroll.minimumZoomScale = 1;

myScroll.clipsToBounds = YES;
CGRect frame2 = myImage.frame;

frame2.origin.y=frame2.origin.y+40;
myScroll.contentOffset=frame2.origin;



myScroll.delegate = self;

[myScroll addSubview:myImage];  

    [myScroll.superview addSubview:toolbar];    

所以工具栏上设置的框架不起作用...并且它在整个屏幕上设置自己...

我不想扩展 UIScrollView,因为我想要一些按钮与此类功能相关。

我想要完成的功能是具有可缩放、可平移的照片和一些选项,用于评论、投票和上一页。接下来等等..从工具栏替代文本http://www.freeimagehosting.net/image .php?ef28ce0bb4.jpg

这是预览:

i'm having a BIG problem that i don't know how to solve...

my UIToolbar that is supposed to be fixed @ the bottom of the screen , appears scaled thorugh all the screen.

In my case i have:

an UIViewController

with an image scroling with an UIScrollView.

so i need the toolbar on the bottom of the screen but instead , it replaces the image scrolling and ocupies all the screen. This happened when i moved from V2 to V3 of the iphone Xcode..before it was showing ok...

I will briefly explain how i'm initializing the things:
in the h file UIScrollView *myScroll;
in the .M file i have
UIToolbar *toolbar;

then on the (void)viewDidLoad {

toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleDefault;

toolbar.frame = CGRectMake(0, 410, 320, 50);
------------------------

myScroll.contentSize = CGSizeMake(myImage.frame.size.width, myImage.frame.size.height);

myScroll.maximumZoomScale = 4.0;
myScroll.minimumZoomScale = 1;

myScroll.clipsToBounds = YES;
CGRect frame2 = myImage.frame;

frame2.origin.y=frame2.origin.y+40;
myScroll.contentOffset=frame2.origin;



myScroll.delegate = self;

[myScroll addSubview:myImage];  

    [myScroll.superview addSubview:toolbar];    

so the frame set on the toolbar doesn't work...and it sets itself over the whole screen...

i would prefer not to extend the UIScrollView, because i want to have some buttons that are related to this class functions..

The functionality i want to acomplish is having a zoomable, panable photo and some options, to comment, and vote , and prev. next etc..from the toolbaralt text http://www.freeimagehosting.net/image.php?ef28ce0bb4.jpg

here's a preview:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞎闹 2024-08-27 12:08:37

最简单的方法是使用 Interface Builder 设置工具栏。

只需将 UIToolbar 放入窗口中并将其连接到视图控制器即可。以下是如何以编程方式设置按钮,但您也可以轻松地将它们添加到 IB 中并在那里连接它们。

- (void)viewDidLoad {
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] 
                              initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                              target:self 
                              action:@selector(insertNewObject)];

    NSArray *items = [NSArray arrayWithObject:addButton];
    self.toolbar.items = items;
}

The easiest way to do this is to use Interface Builder to set up your toolbar.

Just drop a UIToolbar in your window and hook it up to your view controller. Here's how you set up the buttons programmatically, but you could just as easily add them in IB and wire them up there.

- (void)viewDidLoad {
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] 
                              initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                              target:self 
                              action:@selector(insertNewObject)];

    NSArray *items = [NSArray arrayWithObject:addButton];
    self.toolbar.items = items;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文