在过去的3到4个小时里,我一直把头撞在墙上,我似乎无法弄明白.我有一个UIViewController,里面有一个全屏UITableView(屏幕上有一些其他的东西,这就是为什么我不能使用UITableViewController)我想让我的tableHeaderView用autolayout调整大小.不用说,它不合作.
见下面的截图.

因为overviewLabel(例如"此处列出概述信息."文本)具有动态内容,所以我使用autolayout来调整它的大小和它的超级视图.除了tableHeaderView之外,我已经很好地调整了所有内容,它位于层次结构中的Paralax Table View之下.
我发现调整标题视图大小的唯一方法是以编程方式,使用以下代码:
CGRect headerFrame = self.headerView.frame;
headerFrame.size.height = headerFrameHeight;
self.headerView.frame = headerFrame;
[self.listTableView setTableHeaderView:self.headerView];
Run Code Online (Sandbox Code Playgroud)
在这种情况下,headerFrameHeight是tableViewHeader高度的手动计算,如下所示(innerHeaderView是白色区域,或者第二个"View",headerView是tableHeaderView):
CGFloat startingY = self.innerHeaderView.frame.origin.y + self.overviewLabel.frame.origin.y;
CGRect overviewSize = [self.overviewLabel.text
boundingRectWithSize:CGSizeMake(290.f, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName: self.overviewLabel.font}
context:nil];
CGFloat overviewHeight = overviewSize.size.height;
CGFloat overviewPadding = ([self.overviewLabel.text length] > 0) ? 10 : 0; // If there's no overviewText, eliminate the padding in the overall height.
CGFloat headerFrameHeight = ceilf(startingY + overviewHeight + overviewPadding + 21.f + 10.f);
Run Code Online (Sandbox Code Playgroud)
手动计算有效,但如果将来发生变化,它会很笨拙并容易出错.我想要做的是让tableHeaderView根据提供的约束自动调整大小,就像你可以在其他地方一样.但对于我的生活,我无法弄明白.
关于这个问题有几个关于此的帖子,但没有一个是明确的,最后让我更加困惑.这里有几个:
我已经安装了Android的SwipeRefreshLayout,并尝试自定义所有拉动中的颜色以刷新整个应用程序.为了遵循DRY原则,我尝试将所需的颜色移动到array.xml,如下所示:
<resources>
<array name="swipeRefreshColors">
<item>@color/pink</item>
<item>@color/green</item>
</array>
</resources>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将它们导入滑动刷新时:
swipeRefreshLayout.setColorSchemeResources(R.array.swipeRefreshColors);
Run Code Online (Sandbox Code Playgroud)
我得到一个Resources $ NotFoundException:
android.content.res.Resources$NotFoundException: Resource ID #0x7f060001
at android.content.res.Resources.getValue(Resources.java:1233)
at android.content.res.Resources.getColor(Resources.java:887)
at android.support.v4.widget.SwipeRefreshLayout.setColorSchemeResources(SwipeRefreshLayout.java:477)
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一些东西,比如子类化SwipeRefreshLayout代码并对那里的颜色进行硬编码,但它绝对是一个黑客.必须有一种方法可以从Activity中引用一系列颜色来自定义它.
任何帮助将不胜感激!
我正在尝试使用Javascript解析用户输入字符串的持续时间(秒).
以下是我希望能够处理的一些示例输入:
关键组件是1)天,2)小时3)分钟,但可能并不总是包括一些组件.
我的攻击计划是使用.match和regex.只要我能得到单词的第一个字母,我就会知道前面的数字是什么,并且能够处理所有不同格式的单词(例如小时,小时,小时,小时).但是,因为我正在学习正则表达式,所以它比我想象的要复杂得多.
任何帮助或建议将不胜感激!
我觉得这应该是微不足道的,但我似乎无法在手机屏幕上显示通知 - 它只显示在顶部的状态栏中.
有关我想要做的一个例子,这里是Facebook Messenger在收到消息时在屏幕上显示的方式.

每当我发送通知时,它所做的就是在状态栏中显示小图标 - 即使我将优先级设置为PRIORITY_MAX.我需要做另一个设置才能让它显示在屏幕上而不仅仅是状态栏吗?
通知显示代码:
PendingIntent contentIntent = PendingIntent.getActivity(context, nextId++, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Builder builder = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(description)
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_stat_notification)
.setLargeIcon(largeIcon)
.setPriority(Notification.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL);
if (android.os.Build.VERSION.SDK_INT >= 21) {
builder.setColor(context.getResources().getColor(R.color.orange_500))
.setVisibility(Notification.VISIBILITY_PUBLIC);
}
Notification notification = builder.build();
notificationManager.notify(id, notification);
Run Code Online (Sandbox Code Playgroud) 这似乎应该是微不足道的,但我无法弄清楚如何为我的生活中的编程方式设置FrameLayout的子项的layout_gravity.
在SO上有很多类似的问题,但在尝试了其中的10个之后,setGravity,新的FrameLayout.LayoutParams等解决方案似乎都无法正常工作.
下面是我想要实现的简化版本.
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextureView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
但是,出于外部原因,我正在以编程方式将TextureView添加到FrameLayout.
mCameraPreview = new CameraPreview(this, recordMode);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview_wrapper);
preview.addView(mCameraPreview);
Run Code Online (Sandbox Code Playgroud)
当我尝试在mCameraPreview上设置layout_gravity时,它只给我一个重力选项,这是我不想要的.
这里有什么我想念的吗?
如何使tableHeaderView 的背景清晰,但保持UITableView背景的其余部分不透明?
我正在使用透明tableHeaderView来实现paralax效果.tableView后面的对象比clear tableHeaderView"窗口"长,所以我可以将可见数据居中.这适用于较长的列表,因为我可以使用tableView作为掩码,但是当我在表中没有足够的单元格时,背景对象显示在单元格下方.
相关代码:
self.tableView.backgroundView = nil;
self.tableView.backgroundColor = [UIColor whiteColor];
UIView *tableHeaderView = [[UIView alloc] initWithFrame: CGRectMake(0.0, 0.0, 320.0, 250.0)];
tableHeaderView.backgroundColor = [UIColor clearColor];
self.tableView.tableHeaderView = tableHeaderView;
Run Code Online (Sandbox Code Playgroud)
我已经尝试为tableView设置背景颜色,但这会使整个UITableView不透明(包括tableHeaderView),删除顶部的"窗口".
关于如何在设置UITableView的主体不透明时保持透明tableHeaderView的任何想法?
谢谢!
我一直在使用Meteor + Iron Router来处理我正在研究的多页面应用程序,而且我已经陷入了关于命名率的辅助函数.具体来说,我一直试图让我的导航栏选项卡的活动类更新每个路由更改.
以下是我项目的相关代码:
Router.configure({
layoutTemplate: 'mothership',
yieldTemplates: {
'header' : {to: 'header'},
'footer': {to: 'footer'}
},
});
Router.map(function () {
// Home page
this.route('home', {
path: '/',
template: 'home',
});
this.route('about', {
path: '/about',
template: 'about',
});
this.route('emails', {
path: '/emails',
template: 'emails',
});
this.route('people', {
path: '/people',
template: 'people',
});
});
Run Code Online (Sandbox Code Playgroud)
<template name="mothership">
<a href="#content" class="sr-only">Skip to content</a>
<div id="wrap">
<!-- header -->
<div>{{yield 'header'}}</div>
<div id="content">{{yield}}</div>
</div>
<div id="push"></div>
<div id="footer">
{{yield 'footer'}}
</div> …Run Code Online (Sandbox Code Playgroud) android ×3
ios ×2
uitableview ×2
autolayout ×1
ios7 ×1
iron-router ×1
java ×1
javascript ×1
meteor ×1
regex ×1