首页 \ 问答 \ 如何设置元素的宽度等于窗口的宽度?(How to set an element's width equal to window's width?)

如何设置元素的宽度等于窗口的宽度?(How to set an element's width equal to window's width?)

使用:

 $(my_div).width(window.innerWidth)

没有提供所需的结果,因为它没有考虑垂直滚动条,因此元素溢出窗口,创建一个水平滚动条,如下图所示。

插图http://dl.dropboxusercontent.com/u/62862049/Screenshots/om.png


Using:

 $(my_div).width(window.innerWidth)

Does not provide the desired result, because it does not account for the vertical scrollbar, so the element overflows the window, creating a horizontal scrollbar, as illustred below.

Illustration http://dl.dropboxusercontent.com/u/62862049/Screenshots/om.png


原文:https://stackoverflow.com/questions/16986941
更新时间:2023-04-25 15:04

最满意答案

你的故事板应该是这样的

在你的appDelegate.m里面你的didFinishLaunchingWithOptions

//authenticatedUser: check from NSUserDefaults User credential if its present then set your navigation flow accordingly

if (authenticatedUser) 
{
    self.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];        
}
else
{
    UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LoginViewController"];
    UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];

    self.window.rootViewController = navigation;
}

在SignUpViewController.m文件中

- (IBAction)actionSignup:(id)sender
{
    AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];

    appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
}

在文件MyTabThreeViewController.m

- (IBAction)actionLogout:(id)sender {

    // Delete User credential from NSUserDefaults and other data related to user

    AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];

    UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LoginViewController"];

    UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
    appDelegateTemp.window.rootViewController = navigation;

}

Here is what I ended up doing to accomplish everything. The only thing you need to consider in addition to this is (a) the login process and (b) where you are storing your app data (in this case, I used a singleton).

Storyboard showing login view controller and main tab controller

As you can see, the root view controller is my Main Tab Controller. I did this because after the user has logged in, I want the app to launch directly to the first tab. (This avoids any "flicker" where the login view shows temporarily.)

AppDelegate.m

In this file, I check whether the user is already logged in. If not, I push the login view controller. I also handle the logout process, where I clear data and show the login view.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    // Show login view if not logged in already
    if(![AppData isLoggedIn]) {
        [self showLoginScreen:NO];
    }

    return YES;
}

-(void) showLoginScreen:(BOOL)animated
{

    // Get login screen from storyboard and present it
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    LoginViewController *viewController = (LoginViewController *)[storyboard instantiateViewControllerWithIdentifier:@"loginScreen"];
    [self.window makeKeyAndVisible];
    [self.window.rootViewController presentViewController:viewController
                                             animated:animated
                                           completion:nil];
}

-(void) logout
{
    // Remove data from singleton (where all my app data is stored)
    [AppData clearData];

   // Reset view controller (this will quickly clear all the views)
   UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
   MainTabControllerViewController *viewController = (MainTabControllerViewController *)[storyboard instantiateViewControllerWithIdentifier:@"mainView"];
   [self.window setRootViewController:viewController];

   // Show login screen
   [self showLoginScreen:NO];

}

LoginViewController.m

Here, if the login is successful, I simply dismiss the view and send a notification.

-(void) loginWasSuccessful
{

     // Send notification
     [[NSNotificationCenter defaultCenter] postNotificationName:@"loginSuccessful" object:self];

     // Dismiss login screen
     [self dismissViewControllerAnimated:YES completion:nil];

}

相关问答

更多
  • 首先,您应该注意,根据Apples开发人员的说明,您不应该继承UINavigationController的子类。 其次,这是基于意见的,但我建议您应该使用您的应用程序委托类作为检查登录状态的支柱点,它是UINavigationController的单例,实际上是。 OK so here is what I ended up doing: As pointed out by John Woods, don't subclass UINavigationController. Instead, I creat ...
  • 在你的appDelegate.m里面你的didFinishLaunchingWithOptions //authenticatedUser: check from NSUserDefaults User credential if its present then set your navigation flow accordingly if (authenticatedUser) { self.window.rootViewController = [[UIStoryboard storybo ...
  • 将loginVC作为根视图控制器,如下所示: let loginVC = self.storyboard?.instantiateViewController(withIdentifier: "LoginVC") as! LoginVC let appDel:AppDelegate = UIApplication.shared.delegate as! AppDelegate appDel.window?.rootViewController = loginVC Make loginVC as root ...
  • 使用Parse 。 这真的很简单...... Parse是一个适用于iOS的SDK,它允许您执行各种操作,并使用其非常棒的免费实现包来完成用户帐户的管理。 Parse SDK附带一个完全可自定义的登录和注册控制器,可与您的应用程序的在线用户数据库链接。 他们有精彩的教程,你可以在这里查看他们的文档。 编辑: 在请求之后,这里是一个类似SO问题的链接,其中有一个更以登录为中心的答案: 如何制作像Facebook应用程序一样的登录屏幕? I ended up with Building a View Contr ...
  • 正如文件所说 如果使用cookie来传播会话ID(默认行为),则必须删除会话cookie。 setcookie()可能会用于此。 if (ini_get("session.use_cookies")) { $params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params[ ...
  • 感谢Brad Dwyer提供的调试信息,我们将问题范围缩小到Facebook模块和iOS 6帐户框架之间的交互。 我们的v1.4.46平台版本修复了该问题 Thanks to debug information provided by Brad Dwyer we narrowed down the issue to the interaction between the Facebook module and the iOS 6 accounts framework. The problem is fixe ...
  • If(Login Successful){ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil]; HomeViewController* viewController = [storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"]; [self presentV ...
  • 这里的问题是,如果他们使用GET方法访问页面,则不会检查他们是否已登录。 您需要进行如下更改: def GET(self): if session.logged_in: last_login = web.cookies().get('time') if last_login == None: last_login_data = u'ZalogowaĹ‚eĹ› siÄ™ pierwszy raz.' else: ...
  • 我在我们的应用程序中实现了这一点。 在此,我们会在添加新商家信息时将通知发送给用户。 用户可以同时从多个设备登录。 设备可能是android或ios任何东西。 此外,多个用户可以从同一设备登录(登出以前的用户后)。 用户从Android设备登录时,将从GCM获取注册ID。 对于一个设备,此GCM ID不是常量,只要您再次从GCM服务器请求它,它就会更改。 我们使用通知密钥将通知发送到多个设备,它包含所有设备的GCM寄存器ID。 如果您丢失了通知密钥,则无法将其恢复。 更糟糕的是,您无法使用以前使用的通知密钥 ...
  • 用户再次登录后,您希望应用程序在哪里? 假设您希望应用程序位于设置按钮所在的视图控制器(它从故事板中看起来如此)。 那个vc(导航控制器中的根vc)可以这样做: - (void)viewDidAppear:(BOOL)animated { if (/*login is needed*/) { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)