告诉Android onCreate()在方向改变时不打电话我遇到了麻烦.我已经添加android:configChanges="orientation"到我的清单中但仍然onCreate()调用了方向更改.这是我的代码.
AndroidManifest.xml中
<activity android:name="SearchMenuActivity" android:theme="@android:style/Theme.NoTitleBar" android:configChanges="orientation"></activity>
Run Code Online (Sandbox Code Playgroud)
SearchMenuActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the current layout to the search_menu
setContentView(R.layout.search_menu_activity);
Log.d(TAG, "onCreate() Called");
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
//don't reload the current page when the orientation is changed
Log.d(TAG, "onConfigurationChanged() Called");
super.onConfigurationChanged(newConfig);
}
Run Code Online (Sandbox Code Playgroud)
和我的LogCat输出
06-23 12:33:20.327: DEBUG/APP(2905): onCreate() Called
//Orientation Changes
06-23 12:33:23.842: DEBUG/APP(2905): onCreate() Called
Run Code Online (Sandbox Code Playgroud)
有谁知道我做错了什么?谢谢.
我希望在我的ipad应用程序中实现一个布局,它有一个非常适合的视图,可以向左和向右滚动,而不是向上和向下滚动:
所以而不是
第1行第2行第3行(垂直滚动)它将是:第1行,第2行,第3行(水平滚动)
我已经看到UItableView被设计为仅进行垂直滚动,因此进行转换不会产生预期的效果.是否有一种标准方法可以利用uitableview提供的数据源提供商?
我基本上想做的事情类似于Ipad上的BBC新闻阅读器应用程序与故事列表可供选择.
谢谢
我使用以下代码来保存和加载我从库中选择的图像或使用相机:
//saving an image
- (void)saveImage:(UIImage*)image:(NSString*)imageName {
NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]]; //add our image to the path
[fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally …Run Code Online (Sandbox Code Playgroud) 我的故事板iOS应用程序中有一个UICollectionView.当设备处于纵向方向时,我希望它能够垂直滚动,当它在Landscaper中时,我希望它能够水平滚动.
在UICollectionView中,我可以看到scrollEnabled成员,但我看不到设置滚动方向的方法.我错过了什么吗?
在这种情况下我不需要指定方向,我只需要检测它,但我遇到了麻烦.我有条件代码,只能在肖像中工作,如果设备在横向,我需要做其他事情.由于deviceOrientation不一定与interfaceOrientation相同,我无法想出一种测试纵向模式的方法.
我在Google上找到的大多数教程都是强制横向或进行某种轮换的方法.我唯一想做的就是确定方向是什么.这是我的代码,它不起作用:
-(void)viewDidLoad {
[super viewDidLoad];
//currentOrientation is declared as UIInterfaceOrientation currentOrientation
currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
NSLog(@"%@",currentOrientation); // == NULL
}
Run Code Online (Sandbox Code Playgroud)
我需要有条件地确定interfaceOrientation和program的值.谢谢你的帮助!
我一直在试图让我的头发试图让AVFoundation相机以正确的方向(即设备方向)拍摄图片,但我无法让它工作.
我看过教程,我看过WWDC演示文稿,我已经下载了WWDC示例程序,但即便如此也没有.
我的应用程序的代码是......
AVCaptureConnection *videoConnection = [CameraVC connectionWithMediaType:AVMediaTypeVideo fromConnections:[imageCaptureOutput connections]];
if ([videoConnection isVideoOrientationSupported])
{
[videoConnection setVideoOrientation:[UIApplication sharedApplication].statusBarOrientation];
}
[imageCaptureOutput captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error)
{
if (imageDataSampleBuffer != NULL)
{
//NSLog(@"%d", screenOrientation);
//CMSetAttachment(imageDataSampleBuffer, kCGImagePropertyOrientation, [NSString stringWithFormat:@"%d", screenOrientation], 0);
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[self processImage:image];
}
}];
Run Code Online (Sandbox Code Playgroud)
(processImage使用与WWDC代码相同的writeImage ...方法)
并且WWDC应用程序的代码是......
AVCaptureConnection *videoConnection = [AVCamDemoCaptureManager connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
if ([videoConnection isVideoOrientationSupported]) {
[videoConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];
}
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if …Run Code Online (Sandbox Code Playgroud) 是否可以更改genymotion模拟器的方向?是否有拍摄或设置来改变这个?
我试图谷歌它但没有找到它.任何建议将不胜感激,谢谢.
是否有可靠的方法来锁定所有Android设备上的屏幕方向?以下代码适用于我的Nexus S和其他手机,但出于某种原因,ROTATION_90对应于Xoom上的SCREEN_ORIENTATION_REVERSE_PORTRAIT.
有没有办法可靠地将旋转映射到方向?
private void lockScreenOrientation() {
if (!mScreenOrientationLocked) {
final int orientation = getResources().getConfiguration().orientation;
final int rotation = getWindowManager().getDefaultDisplay().getOrientation();
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
}
else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}
}
mScreenOrientationLocked = true;
}
}
private void unlockScreenOrientation() { …Run Code Online (Sandbox Code Playgroud) 我正在通过各种实践来处理线程和AsyncTask的方向更改.我遇到了以下解决方案:
有没有其他方法来处理这种情况?建议的做法是什么?我问这个是因为我在Android文档的任何地方都找不到通用的解决方案.
orientation ×10
iphone ×5
android ×4
ipad ×3
objective-c ×2
rotation ×2
avfoundation ×1
camera ×1
emulation ×1
fragment ×1
genymotion ×1
ios ×1
java ×1
landscape ×1
locking ×1
screen ×1
scroll ×1
uiimageview ×1
whitespace ×1