我有一个带有键"allow_reorientation"的CheckBoxPreference.如果启用,则我的主要活动应在设备旋转时重新定向,如果禁用,则应保持其当前方向.我在manifest.xml中设置了'android:configChanges ="orientation"',以允许自定义处理方向更改.
从我的主要活动课:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
if (preferences.getBoolean("allow_reorientation", true)) {
switch(newConfig.orientation) {
case Configuration.ORIENTATION_PORTRAIT:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
case Configuration.ORIENTATION_LANDSCAPE:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
default:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我以纵向方式启动应用程序,然后将设备旋转到横向,则调用上面的代码并按照需要运行.但是,当旋转回到肖像时,根本不调用该方法,当然视图仍保持在横向中.
我的第一个猜测是因为我没有将'newConfig.orientation'存储在任何地方,所以第二次重新定位回到肖像是将最新的方向值与仍然显示纵向方向的预先存在的值进行比较,因此未检测到配置更改.但是,如果这是真的,那么当我尝试第二次定向到景观时,我在上述方法中设置的断点将被激活,但在这种情况下从不调用该方法.
有人可以澄清一下发生了什么,并提供补救措施吗?
非常感谢.
解决方案 - 谢谢下面的Matthew Willis
在YourApp中扩展应用程序:
public void updateOrientationConfiguration(Activity activity) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
if (preferences.getBoolean("allow_reorientation", true)) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
} else {
if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在YourActivity中扩展Activity:
public void onResume() …
Run Code Online (Sandbox Code Playgroud) 我已经构建了一个自定义的 Ruby gem。调用它MyGem
,然后文件lib/innermodule.rb
包含:
module MyGem
module InnerModule
def self.foo(); puts "Hello world!"; end
end
end
Run Code Online (Sandbox Code Playgroud)
要从另一个正在开发的 gem 中引用它,我必须这样做:
require 'mygem'
require 'innermodule'
Run Code Online (Sandbox Code Playgroud)
这是正常行为,还是 gemspec 有问题MyGem
?
我正在尝试实现最简单的事情 - 创建一个UIScrollView,它可以填充(并且完全适合)应用程序框架(即屏幕减去状态栏高度),而不管设备方向如何.
这证明非常具有挑战性 - 滚动视图似乎不愿意在横向视图中正确调整大小,我不确定为什么.
我决定忘记使用应用程序框架,只是尝试填充屏幕,忽略状态栏高度,但即使这是不可能的.
你可以在下面看到我正在使用的方法.有人会善意地证明如何正确地做到这一点吗?我似乎永远遇到了正确调整对象大小的问题,特别是在尝试完全填充iPhone/iPad屏幕时.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
CGFloat viewedWidth, viewedHeight;
const CGSize dim = [UIScreen mainScreen].bounds.size;
if (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
viewedWidth = dim.width;
viewedHeight = dim.height;
} else {
viewedWidth = dim.height;
viewedHeight = dim.width;
}
[self.scrollView setFrame:CGRectMake(0.0f, 0.0f, viewedWidth, viewedHeight)];
}
-(void)viewDidLoad {
[self.view setFrame:[UIScreen mainScreen].bounds];
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,1,1)];
[self.scrollView setDelegate:self];
[self.view addSubview:self.scrollView];
[self.scrollView setContentSize:sizeManager.canvasSize];
[self didRotateFromInterfaceOrientation:UIInterfaceOrientationPortrait]; // NOTE: orientation passed is not used, dummy
}
Run Code Online (Sandbox Code Playgroud)
非常感谢您的建议,非常感谢.
除非我为我创作和使用的每个模板化类/方法/函数都包含显式模板实例,否则我的任何一个C++项目都会生成链接器错误.
STL课程似乎没有这样的问题.
是否有一些简单的行为准则(双关语)我可以坚持哪些允许像STL那样的延迟实例化?
谢谢收听.
我有一个顶点属性数组GLfloat *vxData
.我既结合GL_ARRAY_BUFFER
并GL_ELEMENT_ARRAY_BUFFER
与vxData
和正确的索引数据和初始顶点渲染成功.
在每个渲染步骤中,我做:
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glBufferData(GL_ARRAY_BUFFER, vxDataSize, vxData, GL_STATIC_DRAW);
glDrawElements(...)
Run Code Online (Sandbox Code Playgroud)
在某个阶段,vxData
更改大小以容纳更少/更多的顶点,重新创建索引数据以反映这一点,并vxDataSize
进行更新.对于数据更改后的渲染,简单地调用上面的相同行是否正确?
我知道其他可能性,例如使用glMapBufferOES
,我只想知道上述在这种情况下技术上是否正确.
给定根目录,我希望识别任何.svn目录和pom.xml中最浅的父目录.
为此,我定义了以下功能
use File::Find;
sub firstDirWithFileUnder {
$needle=@_[0];
my $result = 0;
sub wanted {
print "\twanted->result is '$result'\n";
my $dir = "${File::Find::dir}";
if ($_ eq $needle and ((not $result) or length($dir) < length($result))) {
$result=$dir;
print "Setting result: '$result'\n";
}
}
find(\&wanted, @_[1]);
print "Result: '$result'\n";
return $result;
}
Run Code Online (Sandbox Code Playgroud)
..因此称呼它:
$svnDir = firstDirWithFileUnder(".svn",$projPath);
print "\tIdentified svn dir:\n\t'$svnDir'\n";
$pomDir = firstDirWithFileUnder("pom.xml",$projPath);
print "\tIdentified pom.xml dir:\n\t'$pomDir'\n";
Run Code Online (Sandbox Code Playgroud)
有两种情况我无法解释:
$result
嵌套子例程中感知的值将wanted
持续到下一次调用firstDirWithFileUnder
.因此,当pom搜索开始时,虽然该行my $result = 0;
仍然存在,但wanted
子例程将其值视为上次 …我想创建Double
其值最接近但大于的值Float.MAX_VALUE
.
我刚刚写与此类似,但对于问题Double
和Long.MAX_VALUE
,看这里.
如何重复转换Double
和Float.MAX_VALUE
使用标准Java 6 API?
我的尝试在下面,但似乎不正确:
Long longValue = Long.valueOf(Float.floatToIntBits(Float.MAX_VALUE));
Double value = Double.longBitsToDouble(Double.doubleToLongBits(longValue)+1);
if (value < -Float.MAX_VALUE || value > Float.MAX_VALUE) {
// Code here should execute but does not.
}
Run Code Online (Sandbox Code Playgroud)
真诚的谢谢.
我创建了一个从普通字符串生成属性字符串的方法.在attrString
低于价值是它的内容非空和正确的.
在运行我的应用程序时,第二行失败了EXC_BAD_ACCESS
.知道为什么吗?
该__bridge_retained
呼叫是iOS 5的要求.我也试过,__bridge
但没有效果,问题仍然存在.
NSMutableAttributedString *attrString = (NSMutableAttributedString*)[textLayer attributedString];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge_retained CFMutableAttributedStringRef)attrString);
Run Code Online (Sandbox Code Playgroud)
UPDATE
如果我做:
NSMutableAttributedString *attrString = (NSMutableAttributedString*)[textLayer attributedString];
NSLog(@"%@", attrString);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFMutableAttributedStringRef)attrString);
Run Code Online (Sandbox Code Playgroud)
然后该NSLog
行将无法编译; Xcode给出了警告和错误说明"Incompatible pointer types passing 'char[3]' to parameter of type 'NSString *'"
.
所以我尝试了这个:
NSLog([attrString description]);
Run Code Online (Sandbox Code Playgroud)
这给出了以下输出(我用<snipped>
隐私替换了字符串内容):
2012-01-19 06:49:11.307 WritePath[2475:707] <Snipped>
{
CTForegroundColor = "<CGColor 0x281530> [<CGColorSpace 0x22d1a0> (kCGColorSpaceDeviceRGB)] ( 0 0 0 1 )"; …
ios ×2
android ×1
attributes ×1
c++ ×1
closures ×1
deferred ×1
double ×1
environment ×1
fill ×1
gem ×1
java ×1
module ×1
objective-c ×1
opengl-es ×1
orientation ×1
perl ×1
require ×1
resize ×1
ruby ×1
stl ×1
string ×1
subroutine ×1
templates ×1
uiscrollview ×1
vertex ×1