【问题标题】:UIScrollView and UIButton are not visibleUIScrollView 和 UIButton 不可见
【发布时间】:2015-11-12 03:47:04
【问题描述】:

我的 ViewControl 上有一个 UIButton 和 UIScrollView(它们都安排在 ViewController 的最顶部)

这是 .m 文件中的代码,它包括动画、约束和 UIwebView url 请求。

#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIWebView *webView2;
@implementation ViewController
@synthesize scrollView;

- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    draw1 = 0;

    scrollView.frame = CGRectMake(0, 300, 480, 55);

    [scrollView setContentSize:CGSizeMake(480, 55)];



    openMenu.frame = CGRectMake(220, 270, 60, 30);

    // stuff************************************************************************************************************************






    [super viewDidLoad];



            UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];




    NSString *url=@"http://test.bithumor.co/test26.php";



    NSURL *nsurl=[NSURL URLWithString:url];



    NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];



    [webview loadRequest:nsrequest];



    [self.view addSubview:webview];

    webview.scrollView.bounces = NO;

    // Do any additional setup after loading the view, typically from a nib.

    UIWebView *webview2=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];

    NSString *url2=@"http://google.com";

    NSURL *nsurl2=[NSURL URLWithString:url2];

    NSURLRequest *nsrequest2=[NSURLRequest requestWithURL:nsurl2];

    [webview2 loadRequest:nsrequest2];

    webview2.scrollView.bounces = NO;





        // stuff************************************************************************************************************************
}

- (void)viewDidAppear:(BOOL)animated

{

    [super viewDidAppear:animated];

    draw1 = 1;

}



- (IBAction)OpenMenu:(id)sender {

    if (draw1 ==0) {

        draw1 = 1;

        [UIView animateWithDuration:0.5

                              delay:0.0

                            options: UIViewAnimationOptionCurveEaseOut


                         animations:^{

                             scrollView.frame = CGRectMake(0, 1000, 568, 200);

                             openMenu.layer.frame = CGRectMake(self.view.center.x - 27, self.view.frame.size.height - 80, 80, 80);

                         }

                         completion:^(BOOL finished){

                             NSLog(@"Done!");

                         }];

    } else {

        draw1 = 0;

        [UIView animateWithDuration:0.5

                              delay:0.0

                            options: UIViewAnimationOptionCurveEaseOut

                         animations:^{

                             scrollView.frame = CGRectMake(0, 300, 568, 200);

                             openMenu.layer.frame = CGRectMake(self.view.center.x - 23, 220, 80, 80);

                         }

                         completion:^(BOOL finished){

                             NSLog(@"Done!");

                         }];

    }

}


@end

问题是当我在模拟器中运行应用程序时,只有 UIwebView 可见(全屏)

如何使 UIscrollView 和 UIButton 在 UIwebView 上方可见?

【问题讨论】:

  • 您从未添加过按钮或滚动视图。您需要在 [self.view addSubview:webview]; 之前添加它
  • 按钮是openMenu

标签: ios objective-c uiscrollview uiwebview


【解决方案1】:

在 viewDidLoad 结束时,尝试将滚动和按钮放在前面

[self.view bringSubviewToFront:webview];
[self.view bringSubviewToFront: openMenu];

【讨论】:

  • 结果:UIwebView 不加载网页。
  • “结果:UIwebView 不加载网页”是什么意思?
  • 这就是我从您的答案中添加代码并在模拟器中运行应用程序后发生的情况。 UIwebView 中的网页没有加载。
  • webview2 你用什么?我认为 webview 已加载,但它位于某些东西的后面
  • 它是用于另一个 ViewController 中的另一个 WebView
猜你喜欢
  • 2011-08-26
  • 2017-05-06
  • 2018-02-04
  • 1970-01-01
  • 1970-01-01
  • 2015-03-05
  • 1970-01-01
  • 2012-11-01
  • 1970-01-01
相关资源
最近更新 更多