在带有UINavigationController的iPad应用程序中,一切都在纵向模式下工作,但在横向模式下,后退按钮有时只能返回半个级别.也就是说,在第一次按下时,标题栏会动画,好像它正在弹出一个控制器,而在第二次按下时,它会弹出内容弹出的动画.
有没有人找到解决方案?这个问题中的矛盾解决方案没有帮助.我在导航控制器中有一个shouldAutorotate方法但没有其他方法.
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)inOrientation {
return YES;
}
Run Code Online (Sandbox Code Playgroud)
编辑:
实际上,第一次单击会弹出内容,第二次单击会弹出导航栏.
我有一个导航控制器的视图,我正在以模态方式显示,我想添加一个形状类似于大多数splitViewControllers中使用的默认左箭头按钮的后退按钮.
我可以创建一个基本按钮,但我真的想要左箭头形状 - 这就是我现在拥有的:
/* set title and nav bar items */
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back To Thumbnails" style:UIBarButtonItemStylePlain target:self action:@selector(backToThumbnails:)] autorelease];
Run Code Online (Sandbox Code Playgroud)
我这里只看到3种款式选择?任何建议都非常感谢!
iphone objective-c uinavigationcontroller uibarbuttonitem ipad
我在loadView中以编程方式创建了一个UIView .该应用程序有一个UITabBarController和UINavigationController.
当标签栏和导航栏都存在时,如何创建自动调整大小的视图?
我目前解决这个问题的方法是计算导航和标签栏控制器的高度,并从主屏幕的高度中减去它们:
float navObjectsHeight = self.tabBarController.tabBar.frame.size.height
+ self.navigationController.navigationBar.frame.size.height;
CGRect mainFrame = CGRectMake(0, 0, screenFrame.size.width,
screenFrame.size.height - navObjectsHeight);
UIView *contentWrapper = [[UIView alloc] initWithFrame:mainFrame];
Run Code Online (Sandbox Code Playgroud) iphone objective-c uitabbarcontroller uiview uinavigationcontroller
我在iOS 5上工作.我无法找到以前在Xcode中找到的基于导航的应用程序模板.
那么我可以使用什么呢?
使用故事板,您无法轻松访问appDelegate中的第一个视图控制器(尽管您prepareForSegue可以轻松地将ManagedObjectContext传递到导航堆栈中.
我已经决定给每个视图控制器(或每个视图控制器的超类)要求Core Data访问一个moc成员:
@synthesize moc = _moc;
@property (nonatomic) __weak NSManagedObjectContext *moc;
Run Code Online (Sandbox Code Playgroud)
我对此感到不安,因为它似乎不是一种非常优雅的方式 - 代码太多了.但直接分配需要在viewControllers数组中指定绝对索引,并在每次ManagedObjectContexts的需求发生更改时更改appDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
// rootView gets a tab bar controller
for(UINavigationController *navController in tabBarController.viewControllers) {
for(UIViewController *viewController in navController.viewControllers) {
if([viewController respondsToSelector:@selector(setMoc:)]) {
[viewController performSelector:@selector(setMoc:) withObject:self.managedObjectContext];
NSLog(@"Passed moc to %@", [viewController description]);
}
}
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
这种方法有哪些缺陷,有更好的方法吗?尝试更通用是否更好:
- (void)assignManagedObjectContextIfResponds:(UIViewController *)viewController {
if([viewController respondsToSelector:@selector(setMoc:)]) {
[viewController performSelector:@selector(setMoc:) withObject:self.managedObjectContext];
NSLog(@"Passed moc to %@", [viewController description]); …Run Code Online (Sandbox Code Playgroud) core-data uitabbarcontroller uinavigationcontroller ios5 uistoryboard
我还没有找到如何使我的视图填充可用空间作为根视图控制器(或推动视图控制器)在一个UINavigationController.我试图在这里使用AutoLayout,但我怀疑这是问题.在我的应用代表中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
ViewController *viewController = [[ViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
在我的 ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.translatesAutoresizingMaskIntoConstraints = NO;
// Do any additional setup after loading the view, typically from a nib.
UILabel *companyLabel = [[UILabel alloc] init];
companyLabel.translatesAutoresizingMaskIntoConstraints = NO;
companyLabel.text = @"We Build It";
companyLabel.backgroundColor = [UIColor redColor];
[self.view addSubview:companyLabel];
NSDictionary *views = NSDictionaryOfVariableBindings(companyLabel);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[companyLabel]" options:0 …Run Code Online (Sandbox Code Playgroud) 我正在努力的应用程序barTintColor在推送新的视图控制器时更改其导航栏.现在我们在目标视图控制器的viewWillAppear:方法中设置了这种颜色,但是我们遇到了一些问题.
按照我们现在这样做的方式,导航栏的颜色突然变化,而其余的条形内容像往常一样动画.我喜欢的是酒吧在源颜色和目标颜色之间淡入淡出.有没有办法用公共Cocoa Touch API实现这一目标?
当我在导航栏上从左向右滑动时,我的导航控制器会弹出一个视图控制器.我已经看过这个问题所以我知道我可以设置...
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
...但它只是禁用导航栏下方视图的滑动,而不是栏本身.
我目前的解决方案是手动找到手势并禁用它.哪个有效,但不确定是否有更好的方法.导航栏似乎没有像这样的属性interactivePopGestureRecognizer.
// This is inside a `UINavigationController` subclass.
for (UISwipeGestureRecognizer *gr in self.navigationBar.gestureRecognizers) {
if ([gr isKindOfClass:[UISwipeGestureRecognizer class]] && gr.direction == UISwipeGestureRecognizerDirectionRight) {
gr.enabled = NO;
}
}
Run Code Online (Sandbox Code Playgroud) uinavigationbar uinavigationcontroller uigesturerecognizer ios ios7
我无法在应用的导航栏中设置自定义左栏按钮项.这是我做的:
let profileImage = UIImage(named: "researcher_icon_selected")
let button = UIBarButtonItem(image: profileImage, style: .plain, target: self, action: #selector(self.viewDidLoad))
self.navigationItem.setLeftBarButton(button, animated: true)
Run Code Online (Sandbox Code Playgroud)
我把这段代码放在我的viewDidLoad中,它是一个名为"ExpertsNavigationViewController"的子类UINavigationController.但导航栏中没有任何内容出现!
以下是我尝试过的一些调试实验:
1)我打印了左侧栏按钮项目图片尺寸,实际上它是我设置的自定义图像的正确尺寸.所以实例就在那里,它只是没有出现在视图中.
2)我在一个全新的XCode项目中尝试了这个,并出现了自定义栏按钮项目!
3)因此我尝试在我当前的项目中创建一个全新的自定义导航控制器,使其成为初始视图控制器,将上面的代码插入其 viewDidLoad中,但同样没有任何显示!
4)我想也许我在App Delegate中做了一些事情,或导航控制器的根视图来改变导航栏.但没有任何东西!
有任何想法吗?我将不胜感激为什么bur按钮项目不会出现的任何提示.谢谢.
我们使用的自定义子类UINavigationController显示自定义视图,而不是UINavigationBar仅显示第一个视图控制器.
为此,我们覆盖pushViewController和popViewController动画出来,在我们的自定义视图.
代码pushViewController看起来像:
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
super.pushViewController(viewController, animated: animated)
defer { showTopViewIfNeeded(animated: animated) }
guard let transitionCoordinator = viewController.transitionCoordinator else { return }
transitionCoordinator.animateAlongsideTransition(in: self.view, animation: { (context) in
let fromViewController = context.viewController(forKey: UITransitionContextViewControllerKey.from)
if fromViewController == self.viewControllers.first {
var navigationViewFrame = self.topNavigationView.frame
navigationViewFrame.origin.x -= navigationViewFrame.size.width
self.topNavigationView.frame = navigationViewFrame
}
}, completion:nil)
}
Run Code Online (Sandbox Code Playgroud)
基本上,我调用了super实现,所以transitionCoordinator创建了一个(nil直到我调用它),然后我在转换的同时为视图设置动画.
它popViewController是相似的,只是反转动画(通过将原点改回零).
我遇到的问题是,第一次按下视图控制器时,动画不会发生.相反,自定义视图的框架会立即更改.
弹出并再次推动时,动画效果很好. …
ios ×4
iphone ×3
objective-c ×3
ios5 ×2
ios7 ×2
ipad ×2
autolayout ×1
core-data ×1
navigation ×1
orientation ×1
swift ×1
uistoryboard ×1
uiview ×1
xcode ×1