简体   繁体   English

此代码仅适用于iPhone Retina 4英寸模拟器

[英]This code only works on iPhone Retina 4-inch simulator

I'm developing an iOS 5+ application with latest SDK and I have a custom UIView with a custom XIB . 我正在使用最新的SDK开发iOS 5+应用程序,并且具有带有自定义XIB的自定义UIView

This is TopMenuView.h : 这是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

This is TopMenuView.m : 这是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

And on UIViewController I do this to show it: 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];
}

And this is the view: 这是视图:

在此处输入图片说明

This code works perfectly only on iPhone Retina 4-inch simulator . 此代码仅在iPhone Retina 4英寸模拟器上完美地工作。 On iPhone Retina 3.5-inch and on iPhone simulator, it doesn't work. 在3.5英寸的iPhone Retina和iPhone模拟器上,它不起作用。

The problem is that I do a click over any of that "buttons" it do nothing. 问题是我单击了所有“按钮”,但没有任何作用。 No Touch Inside Up event is throw (I set a debug point inside the IBAction method). 没有引发Touch Inside Up事件(我在IBAction方法中设置了调试点)。

I haven't test it on a real iPhone because I don't have a developer license yet. 我还没有在真正的iPhone上进行测试,因为我还没有开发者许可证。

What's happening? 发生了什么? Why it doesn't work on iPhone 3.5-inch? 为什么在3.5英寸iPhone上不起作用?

You probably have another view which covers over your buttons. 您可能有另一个覆盖您的按钮的视图。 Check your xib file for a view that is possibly being expanded by the system when it has a different size screen. 检查您的xib文件,以查看当屏幕尺寸不同时,系统可能会在扩展该视图。

I had the same problem. 我有同样的问题。 Everything worked fine, until I uncheck "Use AutoLayout" button in Storyboard. 一切正常,直到取消选中情节提要中的“使用自动版式”按钮。 I have UIView with button placed on it. 我的UIView带有按钮。 And have action related to this button. 并有与此按钮相关的操作。 Then in iPhone Retina 3.5-inch Simulator it doesn't respond to that action. 然后,在iPhone Retina 3.5英寸模拟器中,它不响应该操作。 Finally, I found the solution in the Storyboard. 最后,我在情节提要中找到了解决方案。 It sets the height of my view where button is placed to 0. I don't know why. 它会将放置按钮的视图的高度设置为0。我不知道为什么。 So I just specify its height programmatically. 因此,我只是以编程方式指定其高度。 Hope this will help! 希望这会有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的按钮在iPhone(4英寸视网膜)模拟器上未检测到触摸事件,但在iPhone(3.5英寸视网膜)模拟器中有效 - My button doesn't detect touch events on iPhone (Retina 4-inch) simulator, but works in iPhone (Retina 3.5-inch) simulator 在4英寸iPhone模拟器中显示错误的高度 - Displaying wrong height in 4-inch iPhone simulator 解析错误iPhone Retina(4英寸64位) - Parse Error iPhone Retina (4-inch 64bit) 提取联系人在iPhone Retina 4英寸64位模拟器中不起作用,但在3.5英寸中可以正常工作 - Fetching contact is not working in iphone retina 4inch 64bit simulator but works fine in 3.5 inch 为什么我的Xcode4.5没有iPhone(Retina 4英寸)和iPhone(Retina 3.5英寸) - Why my Xcode4.5 doesn't has iPhone(Retina 4-inch) and iPhone(Retina 3.5inch) 从iPhone 4英寸屏幕xib的iPhone 3.5“模拟器中更改了视框 - View frame changed in the iPhone 3.5" simulator from iPhone 4-inch screen xib iPhone 未在 iPhone 5 模拟器上显示指定的 4 英寸启动图像 - iPhone doesn't show specified 4-Inch launch image on iPhone 5 Simulator iPhone 4英寸屏幕上的屏幕渲染问题 - Screens Rendering Issue on iPhone 4-inch Screen MainWindow.xib和iPhone 5(4英寸显示屏) - MainWindow.xib and iPhone 5 (4-inch display) UIWebView pdf内容未在iPhone 5(4英寸)中调整大小 - UIWebView pdf content is no resized in iPhone 5 (4-inch)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM