我有UIToolbar几个UIBarButtonItems显示各种UIActionSheets使用showFromBarButtonItem:.
在iPad上,当其中一个动作表出现在屏幕上时,触摸动作表外的任何位置都会将其删除而不执行任何操作(例如,触摸按钮不会触发按钮).这是设计 - 我不满意的东西,但我接受它,只要它是通常的行为.
但有一个例外.如果我触摸另一个UIBarButtonItem按钮,则会触发此按钮并且不会从屏幕上删除当前操作表.如果新按钮恰好启动另一个按钮UIActionSheet,我最终会在屏幕上显示两个(或更多)操作表.
当然,我可以通过一个繁琐的过程来记住屏幕上的内容并手动解除它,但我也关注用户,因为一些触摸(那些以工具栏按钮为目标)被尊重而其他人被忽略.
有什么我可以做或者我必须忍受这种情况吗?
有没有办法在iPhone应用程序的UIActionSheet中有超过1个红色"破坏性按钮"?
我需要在同一个操作表中有不同的清除选项,一个删除所有内容,另一个删除较少,所以两者都需要为红色.
我读了很多关于这一点.人们说它不会自动旋转它的父母没有设置为自动旋转.我尝试了一切,但没有运气.我用一个执行此操作的按钮创建了基于视图的应用程序(v4.2):
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel Button" destructiveButtonTitle:@"Destructive Button" otherButtonTitles:@"Other Button 1", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self.view];
Run Code Online (Sandbox Code Playgroud)
根控制器设置为自动旋转.actionSheet没有.请注意,当我旋转模拟器时,不会调用根控制器的方向方法.代表有问题吗?怎么了?
我在一个视图中创建了两个操作表.有两个按钮,每个按钮将启动一个操作表.
问题:当我在两个操作表中按下第一个选项时,会触发相同的操作.
这是我的代码:
-(IBAction) ChangeArrow:(id)sender{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Change Arrow"
delegate:self
cancelButtonTitle:@"cancel"
destructiveButtonTitle:@"Red"
otherButtonTitles:@"Blue",@"Black",nil];
[actionSheet showInView:self.view];
[actionSheet release];}
- (void) actionSheet: (UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex ==[actionSheet destructiveButtonIndex]) {
self.bar.image=[UIImage imageNamed:@"red"];
}
else if(buttonIndex == 1){
self.bar.image=[UIImage imageNamed:@"blue"];
}
else if(buttonIndex == 2){
self.bar.image=[UIImage imageNamed:@"dark"];}
}
Run Code Online (Sandbox Code Playgroud)
//第二个行动表:
-(IBAction) Background:(id)sender{
UIActionSheet *actionSheet2 = [[UIActionSheet alloc] initWithTitle:@"Change Background"
delegate:self
cancelButtonTitle:@"cancel"
destructiveButtonTitle:@"Sky"
otherButtonTitles:@"Thumbs",@"Smiley",nil];
[actionSheet2 showInView:self.view];
[actionSheet2 release];
}
- (void) actionSheet2: (UIActionSheet *)actionSheet2 didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex ==[actionSheet2 destructiveButtonIndex]) {
self.background.image=[UIImage …Run Code Online (Sandbox Code Playgroud) 我使用基于拆分视图的应用程序模板创建了一个新应用程序.
然后我将一个Action Button添加到名为actionButton的rootViewController导航控制器中.
按下按钮时,我会显示如下的ActionSheet:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil
otherButtonTitles:@"Admin Functions", @"Refresh Data", nil];
[actionSheet showFromBarButtonItem:actionButton animated:YES];
[actionSheet release];
Run Code Online (Sandbox Code Playgroud)
在横向模式下按下按钮后,它会在指向按钮的弹出框中显示操作表(正如我预期的那样):

但是,在纵向模式下,它看起来完全不同,菜单从rootViewController popover的底部出现,就像在iPhone上一样:

我的问题是,如何在纵向模式下使ActionSheet显示在顶部,就像在横向模式下一样?
由于这是一个"实用程序菜单",它并不直接与显示的数据绑定,因此它不应该是弹出窗口的一部分.
uiactionsheet ipad uisplitviewcontroller uipopovercontroller ios
我的应用程序有一个视图控制器,无法更改方向.把它想象成一个需要保持固定的运动场.
我现在想要提出一个UIActionSheet,但考虑到用户拿着设备的方式,我想将表单与方向匹配.
似乎UIActionSheet与MFComposerViewController不同,它不是从StatusBar获取它的方向,我根据方向旋转它,但从底层视图控制器获取它的方向.换句话说,UIActionSheet以纵向方式显示,无论设备如何被保持.
我试过了:
CGAffineTransform t = CGAffineTransformMakeRotation(lastUIAngle);
[actionSheet setTransform:t];
if (UIInterfaceOrientationIsLandscape(lastOrientation))
actionSheet.frame = CGRectMake(0, 0, 480, 320);
else
actionSheet.frame = CGRectMake(0, 0, 320, 480);
actionSheet.center = self.view.center;
Run Code Online (Sandbox Code Playgroud)
我设法得到正确的方向,但最终的动作表从纵向侧出现,并且大小就像是纵向还是一样.动作表的框架是根据按钮数等计算的.
有没有人设法迫使UIActionSheet正确显示在指定的方向?
(我也尝试创建一个新的视图,它被转换并具有正确的大小,但是UIActionSheet忽略了它.剩下的是创建一个自动旋转的新UIViewController,并让UIActionSheet成为它的一个孩子.但是,这意味着新的视图控制器完全掩盖了我的比赛场地.)
我有一个UIPickerView,需要让它显示在iPad的UIActionSheet中(它在iPhone中非常直接,而不是在iPad中).
当我点击时,我在视图上有一个按钮我执行以下代码:
- (IBAction) buttonPressed:(id)sender
{
NSLog(@"I am pressed");
UIPickerView* picker = [[UIPickerView alloc] initWithFrame:CGRectMake(100,200,500,500)];
picker.delegate = self;
picker.dataSource = self;
picker.showsSelectionIndicator = YES;
[self.view addSubview:picker];
}
Run Code Online (Sandbox Code Playgroud)
// PickerView委托和数据源函数:
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return 5;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return @"One";
}
Run Code Online (Sandbox Code Playgroud)
但是当更改上面的代码以在ActionSheet中添加PickerView时,它只显示 ActionSheet 的标题,但里面没有PickerView!
修改后的代码如下:
- (IBAction) buttonPressed:(id)sender
{ …Run Code Online (Sandbox Code Playgroud) 我正在创建一个标准UIActionSheet,我不需要破坏性按钮和底部的取消按钮.我的其他按钮标题存储在一个NSArray.
但是,我对行分隔符的行为非常奇怪,特别是当我尝试添加标题时.
我在这里完全失败了.救命?
实施#1(无标题)
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
for (NSString *title in self.myArray) {
[actionSheet addButtonWithTitle:title];
}
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet showFromToolbar:(UIToolbar*)self.toolbarView];
Run Code Online (Sandbox Code Playgroud)
实施#2(带标题)
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
for (NSString *title in self.myArray) {
[actionSheet addButtonWithTitle:title];
}
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet showFromToolbar:(UIToolbar*)self.toolbarView];
Run Code Online (Sandbox Code Playgroud)
结果#1(无标题)
当我有10个或更少的按钮,不包括取消按钮时,所有按钮都适合屏幕.行分隔符扩展了操作表的整个宽度.这是预期的行为.
当我有11个或更多按钮时,操作表实现滚动.分隔符现在一直向左延伸,但在右边留出空间(~25px?).此外,当我向上和向下滚动时,每次在最后一个非取消按钮之后添加/移除额外的分隔符(扩展全宽).
结果#2(标题)
当我有10个或更少的按钮,不包括取消按钮时,所有按钮都适合屏幕.行分隔符扩展了操作表的整个宽度.还有一个分隔符,在顶部标题和第一个按钮之间延伸全宽.这是预期的行为.
当我有11个或更多按钮时,操作表实现滚动.分隔符现在一直向左延伸,但在右边留出空间(~25px?).标题和按钮之间的分隔符在分隔符的两侧留出空间(~5px).现在当我向上和向下滚动时,我得到了非常奇怪的分隔符行为,分隔符在奇怪的地方被添加和删除.
我的问题很简单,但我无法找到解决办法.按下按钮时,我会出现一个带有两个选项(库/相机)的UIActionSheet.当用户按下UIActionSheet上的按钮时,我会使用照片库呈现UIPopoverController或以模态方式呈现相机.
当按下操作表上的按钮时,我在控制台中收到以下警告:
Warning: Attempt to present <UIImagePickerController: 0x17ae1600> on <MyViewController: 0x17a3ca00> which is already presenting <UIAlertController: 0x1884acb0>
关于合适的解决方法的任何想法?
我正在尝试创建一个UIAlertAction,第一个按钮为黑色文本,第二个按钮为蓝色.如果我改变色调然后全部变黑,但是没有它我不能将第一个按钮改为黑色.以下是我的代码:
let alert = UIAlertController(title: "", message: "", preferredStyle: .actionSheet)
// alert.view.tintColor = UIColor.black
alert.addAction(UIAlertAction(title: "First", style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud) uiactionsheet ×10
ios ×7
ipad ×3
iphone ×3
objective-c ×2
autorotate ×1
ios7 ×1
orientation ×1
rotation ×1
swift ×1
uipickerview ×1