【问题标题】:This code only works on iPhone Retina 4-inch simulator此代码仅适用于 iPhone Retina 4 英寸模拟器
【发布时间】:2013-10-16 16:10:22
【问题描述】:

我正在使用最新的 SDK 开发 iOS 5+ 应用程序,并且我有一个自定义 UIView 和一个自定义 XIB

这是TopMenuView.h

#import <UIKit/UIKit.h>

@interface TopMenuView : UIView

@property (weak, nonatomic) IBOutlet UIButton *MenuButton;
@property (weak, nonatomic) IBOutlet UILabel *MenuLabel;
@property (weak, nonatomic) IBOutlet UIButton *SearchButton;
@property (weak, nonatomic) IBOutlet UIButton *ProfileButton;
@property (weak, nonatomic) IBOutlet UIButton *HomeButton;

@property (weak, nonatomic) UIViewController* parentController;

- (IBAction)MenuClicked:(id)sender;
- (IBAction)SearchClicked:(id)sender;
- (IBAction)ProfileClicked:(id)sender;
- (IBAction)HomeClicked:(id)sender;

+ (id)topMenuView;

@end

这是TopMenuView.m

#import "TopMenuView.h"
#import "SearchViewController.h"
#import "ProfileViewController.h"
#import "HomeViewController.h"

#import "SWRevealViewController.h"

@implementation TopMenuView

@synthesize parentController;

+ (id)topMenuView
{
    TopMenuView* topView = [[[NSBundle mainBundle] loadNibNamed:@"TopMenuView"
                                                          owner:nil
                                                        options:nil] lastObject];
    // make sure customView is not nil or the wrong class!
    if ([topView isKindOfClass:[TopMenuView class]])
    {
        [topView setFrame:CGRectMake(0, 0, 320, 49)];
        return topView;
    }
    else
        return nil;
}

#pragma mark -
#pragma mark IBAction methods

- (IBAction)MenuClicked:(id)sender
{
    [self.parentController.revealViewController revealToggle:sender];
}

- (IBAction)SearchClicked:(id)sender
{
    SearchViewController* search =
        [[SearchViewController alloc] initWithNibName:@"SearchViewController"
                                               bundle:nil];

    [self.parentController.revealViewController setFrontViewController:search];
}

- (IBAction)ProfileClicked:(id)sender
{
    ProfileViewController* profile =
        [[ProfileViewController alloc] initWithNibName:@"MyProfileViewController"
                                                bundle:nil];

    [self.parentController.revealViewController setFrontViewController:profile];
}

- (IBAction)HomeClicked:(id)sender
{
    HomeViewController* home =
        [[HomeViewController alloc] initWithNibName:@"HomeViewController"
                                             bundle:nil];

    [self.parentController.revealViewController setFrontViewController:home];
}

@end

UIViewController 我这样做是为了展示它:

- (void)viewDidLoad
{
    [super viewDidLoad];

    topMenuView = [TopMenuView topMenuView];
    topMenuView.MenuLabel.text = @"Home";
    topMenuView.parentController = self;
    [self.view addSubview:topMenuView];

    // Set the gesture to open the slide menu.
    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}

这是视图:

此代码仅适用于 iPhone Retina 4 英寸 模拟器。在 iPhone Retina 3.5 英寸和 iPhone 模拟器上,它不起作用。

问题是我点击任何“按钮”它什么都不做。没有引发 Touch Inside Up 事件(我在 IBAction 方法中设置了一个调试点)。

我还没有在真正的 iPhone 上测试它,因为我还没有开发者许可证。

发生了什么?为什么它在 iPhone 3.5 英寸上不起作用?

【问题讨论】:

    标签: iphone ios objective-c ios-simulator


    【解决方案1】:

    您可能有另一个视图覆盖了您的按钮。检查您的 xib 文件,以查看在屏幕尺寸不同时系统可能正在扩展的视图。

    【讨论】:

    • 我想如果我有另一个视图覆盖我的TopMenuView,它在任何模拟器中都不起作用。
    • 某些东西正在捕捉您的修饰事件,这可能是另一种观点。我认为视图的长度不足以覆盖 4 英寸屏幕上的按钮,但足以覆盖 3.5 英寸屏幕。
    【解决方案2】:

    我遇到了同样的问题。一切正常,直到我取消选中情节提要中的“使用自动布局”按钮。我有 UIView,上面有按钮。并有与此按钮相关的操作。然后在 iPhone Retina 3.5 英寸模拟器中,它不会响应该操作。 最后,我在 Storyboard 中找到了解决方案。它将放置按钮的视图的高度设置为 0。我不知道为什么。所以我只是以编程方式指定它的高度。 希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      相关资源
      最近更新 更多