使用iOS 8和Xcode 6,在故事板中我们现在有了屏幕尺寸网格,让我们选择尺寸等级.您可以在哪里为不同的屏幕尺寸选择布局格式.
我发现这非常有用,因为它允许我设置基本约束,然后为每个屏幕大小设置唯一的约束.
我的问题是,你能以编程方式执行此操作吗?我NSLayoutConstraint
正常创建我,但我需要能够为不同的屏幕尺寸指定不同的约束.
我的应用程序中有多个UITableViews,是否有一种方法可以检测用户在该列中选择的单元格/行?
还可以以编程方式取消选择单元格/行吗?
谢谢.
在我的cocos2d游戏中,我有我的玩家精灵,我希望让他朝我倾斜iPhone的方向移动.我可以解决这个问题,我无法解决的最困难的是:
如何让我的精灵旋转指向我倾斜的方向?这在应用程序商店的"Tilt to Live"游戏中得到了很好的体现.我想要像这样的控件.
我的精灵(对于那些不熟悉cocos2d的人)确实有旋转值,如果有帮助的话.
谢谢.
我在故事板中构建了三个不同的单元格,并将所有出口连接起来,每个单元格都有一个唯一的标识符.
例如,我有一个包含图片的单元格,另一个包含标签的单元格,另一个包含其他内容,因此它们都是唯一的,每个单元格类型都需要自己的高度(动态或状态,无关紧要).
但是,我怎么能用'indentifier1'制作一个单元格返回一定的高度,然后其他单元格返回不同的高度?
我知道我可以使用,- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
但我不确定如何区分细胞.
我正在使用核心数据并从中获取tableview的结果.
我用标签尝试了这个,但它在第一个if
语句崩溃了:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat cellHeight;
if ([[tableView cellForRowAtIndexPath:indexPath] tag] == 1) cellHeight = 170;
else if ([[tableView cellForRowAtIndexPath:indexPath] tag] == 2) cellHeight = 100;
else if ([[tableView cellForRowAtIndexPath:indexPath] tag] == 3) cellHeight = 140;
return cellHeight;
}
Run Code Online (Sandbox Code Playgroud) 我知道这个主题有很多,但我无法获得任何代码.我正在运行iOS5并为iPad构建,我只是无法在导航栏的一侧获得两个按钮.
任何帮助将不胜感激,谢谢.
编辑:
我测试过的一些代码viewDidLoad
,但它没有做任何事情.
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(save)];
UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc] initWithTitle:@"Delete" style:UIBarButtonItemStylePlain target:self action:@selector(delete)];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:saveButton,deleteButton,nil];
Run Code Online (Sandbox Code Playgroud) 我有一个习惯StatefulWidget
,当输入一个空字段时,它会自动在下面添加一个新的空字段,以便用户可以继续添加数据。
但是,当我使用setState
inonChanged
添加新字段时,键盘被关闭并且焦点丢失在当前聚焦的字段上。
Io 如何防止这种情况发生?
TextField(
hintText: widget.newEntryHint,
text: data[index].value,
onChanged: (val) {
setState(() {
data[index].value = val;
//if last item in list, add an extra field below
if (val.length > 0 && index == (data.length -1)) {
data.add(TextListItem(value: ""));
}
});
},
)
Run Code Online (Sandbox Code Playgroud)
自定义 TextField 供参考:
class MyTextField extends StatefulWidget {
MyTextField({
this.text,
this.hintText = "",
this.onChanged,
this.onSubmitted,
this.textAlign = TextAlign.left,
this.focusNode,
this.autofocus = false,
this.obscureText = false,
this.padding = const EdgeInsets.all(0.0),
this.keyboardType = …
Run Code Online (Sandbox Code Playgroud) 我想左右旋转UIImageView
大约10度,但是有一个平滑的动画,而不是我看到的突然转弯:
player.transform = CGAffineTransformMakeRotation(angle)
Run Code Online (Sandbox Code Playgroud)
任何帮助表示感谢,谢谢.
我需要以编程方式在UITableView中设置单个UITableViewCell的高度.我怎样才能做到这一点?
我需要这个单元格高150像素,所有其他单元格可以保持默认的44像素高度.
谢谢.
我已经将音频工具箱和avfoundation导入到我的班级并将框架添加到我的项目中并使用此代码播放声音:
- (void)playSound:(NSString *)name withExtension:(NSString *)extension
{
NSURL* soundUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:name ofType:extension]];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
audioPlayer.delegate = self;
audioPlayer.volume = 1.0;
[audioPlayer play];
}
Run Code Online (Sandbox Code Playgroud)
我称之为:
[self playSound:@"wrong" withExtension:@"wav"];
Run Code Online (Sandbox Code Playgroud)
零声音.非常感谢任何帮助,谢谢.
我试图以编程方式将UINavigationBar添加到UIView并取得如此成功,并且无法弄明白.我试图在我的UIView子类中添加它,它只是在我运行我的应用程序时没有显示.
这是我的代码:
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, headerHeight)];
[navBar setBackgroundColor:[UIColor blueColor]];
[self addSubview:navBar];
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"done" style:UIBarButtonItemStylePlain target:self action:@selector(done:)];
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"categories"];
[navItem setRightBarButtonItem:doneItem animated:YES];
[navBar setItems:[NSArray arrayWithObject:navItem] animated:YES];
Run Code Online (Sandbox Code Playgroud) objective-c ×8
iphone ×6
uitableview ×3
ios ×2
ipad ×2
rotation ×2
animation ×1
audio ×1
autolayout ×1
cell ×1
flutter ×1
focus ×1
ios8 ×1
keyboard ×1
textfield ×1
uiimageview ×1
uiview ×1