我的画廊中有照片,无论是风景还是肖像.在Gallery应用程序中正确显示.当我使用意图从库中选择图片时,我得到了一个URI.但在我显示图片之前,如何知道图片是纵向还是横向?
我的应用程序使用Intent选择图片,如下所示:
private OnClickListener btnChooseFromLibraryListener = new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, REQ_CODE_PICK_IMAGE);
}
};
Run Code Online (Sandbox Code Playgroud)
以下是我如何获得意图:
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case REQ_CODE_PICK_IMAGE:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
SetPicture(filePath);
}
}
}
private void SetPicture(String filePath) { …Run Code Online (Sandbox Code Playgroud) Apple AppleTV应用程序(如电影和电视节目)的常见行为之一是它们以可见的UITabBar开头,并且所有视图的内容都在标签栏下方的空间中呈现.一旦焦点从标签栏移动到屏幕上的某些内容,标签栏就会从屏幕顶部滑出,内容会向上移动/向上滚动以填充现在可用的空间.如果标签栏重新出现,此过程将自行反转.
有没有一种简单的方法来完成这种行为(如复选框或其他东西?),或者我必须didUpdateFocusInContext:withAnimationCoordinator:在各个地方实现该方法,并手动调整框架或滚动内容或东西?
我使用IB来创建一个segue来呈现另一个视图popover.
我添加了一个代码来prepareForSegue将UIPopoverPresentationControllerDelegate释放到初始控制器.
我设置了演示风格:
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController,
traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return UIModalPresentationStyle.None
}
Run Code Online (Sandbox Code Playgroud)
这给了我一个很好的标准弹出窗口.
但是,我想制作一个半透明的popover.
我尝试了几件事:
我的活动需要监控设备的方向.现在这很好用onConfigurationChanged(),但我也需要知道我的Activity开始时的方向.
那么如何找出我的设备的当前方向onCreate()?
我有一个活动,在活动启动时,我需要在lanscape中更改方向,然后我想在用户旋转设备时处理两个方向更改,但是一旦改变方向,稍后就不会改变方向.这是我的代码请帮忙
public class Hls extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hls);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.v("new orientation", "yes");
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
{
Toast.makeText(this, "portrait", Toast.LENGTH_LONG).show();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
Toast.makeText(this, "landscape", Toast.LENGTH_LONG).show();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
Run Code Online (Sandbox Code Playgroud) 在tvOS中,有一个集合视图.每个"行"是一个图像.每个图像都有与之关联的文本.当用户"悬停"在图像上时,文本将更改为与图像匹配.但是,我希望用户能够转到文本而不将焦点放在所选图像和UITextView之间的图像之间.
使用播放/暂停按钮,我可以切换UITextView的背景颜色,但UITextView无法获得焦点.用户必须使用遥控器来选择UTTextView.
这是代码:
- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIEvent *)event {
for (UIPress *item in presses)
{
if(item.type == UIPressTypePlayPause) {
//should reactivate uicollectionview
if (_isPlay) {
_isPlay = NO;
_artistsCollectionView.userInteractionEnabled = YES;
_textViewForBiosAndHelp.backgroundColor = [UIColor lightGrayColor];
[_textViewForBiosAndHelp resignFirstResponder];
[_artistsCollectionView becomeFirstResponder];
[_artistsCollectionView preferredFocusedView];
//the purpsoe is to go to the textview. it does not.
}else{
_isPlay = YES;
_artistsCollectionView.userInteractionEnabled = NO;
_textViewForBiosAndHelp.backgroundColor = _aColor;
[_artistsCollectionView resignFirstResponder];
[_textViewForBiosAndHelp becomeFirstResponder];
[ _textViewForBiosAndHelp preferredFocusedView];
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我在哪里可以找到xcode或sim中tvos javascript的控制台输出?答案可能微不足道,但我无法弄明白.谢谢你的耐心.
我想让应用程序支持所有方向.它的工作正常,但只有颠倒的方向不起作用.我正在使用ios7.对于倒置,视图不会旋转.我试过以下代码
-(BOOL)shouldAutorotate
{
return yes;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll; // etc
}
Run Code Online (Sandbox Code Playgroud)
我唯一的第二种方法是调用但不是第一种方法.在infoPlist中,我启用了所有支持的方向.
我有2个视图控制器注册,以接收设备方向更改通知.`
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(repositionView)name:UIDeviceOrientationDidChangeNotification object:nil];
`
在重新定位视图方法中,我有:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
NSLog(@"view (%@) will set orientation landscape",self);
// do smt
} else {
NSLog(@"view (%@) will set orientation portrait",self);
//do smt else
}
Run Code Online (Sandbox Code Playgroud)
当方向改变时,它们都在记忆中
2013-11-27 17:37:54.277 App[13782:70b] view (<ViewController: 0xbf09950>) will set orientation landscape
2013-11-27 17:37:54.286 App[13782:70b] view (<ViewController: 0xc095e40>) will set orientation portrait
2013-11-27 17:38:17.318 App[13782:70b] view (<ViewController: 0xbf09950>) will set orientation portrait
2013-11-27 17:38:20.123 App[13782:70b] view (<ViewController: 0xc095e40>) will set orientation landscape
Run Code Online (Sandbox Code Playgroud)
只有一个接收正确的方向.为什么是这样 …
所以我有一个自定义类,并为其定义了一个委托方法。这是一个简化的示例:
protocol MyDelegate {
func myDelegateMethod()
}
class Myclass (){
//other stuff
func myDelegateMethod(){
//some operation
}
}
Run Code Online (Sandbox Code Playgroud)
我想从另一个类重写这个方法。我用了
override func myDelegateMethod(){
}
Run Code Online (Sandbox Code Playgroud)
但我收到了这个错误
方法不会覆盖其超类中的任何方法
我明白这是说超类没有实现这个方法,所以我不需要使用关键字override。但就我而言,我确实myDelegateMethod在超级类中MyClass,并且我确实想覆盖它。
那么我怎样才能使这个函数可重写呢?
编辑:
如果你想查看实际的代码,这里是要点