[英]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.