小编Jos*_*ane的帖子

以编程方式设置AutoLayout大小类?

使用iOS 8和Xcode 6,在故事板中我们现在有了屏幕尺寸网格,让我们选择尺寸等级.您可以在哪里为不同的屏幕尺寸选择布局格式.

我发现这非常有用,因为它允许我设置基本约束,然后为每个屏幕大小设置唯一的约束.

我的问题是,你能以编程方式执行此操作吗?我NSLayoutConstraint正常创建我,但我需要能够为不同的屏幕尺寸指定不同的约束.

objective-c autolayout nslayoutconstraint ios8

14
推荐指数
2
解决办法
6174
查看次数

UITableView检测选定的单元格?

我的应用程序中有多个UITableViews,是否有一种方法可以检测用户在该列中选择的单元格/行?

还可以以编程方式取消选择单元格/行吗?

谢谢.

iphone objective-c cell uitableview ipad

13
推荐指数
1
解决办法
2万
查看次数

指向倾斜方向 - iPhone

在我的cocos2d游戏中,我有我的玩家精灵,我希望让他朝我倾斜iPhone的方向移动.我可以解决这个问题,我无法解决的最困难的是:

如何让我的精灵旋转指向我倾斜的方向?这在应用程序商店的"Tilt to Live"游戏中得到了很好的体现.我想要像这样的控件.

我的精灵(对于那些不熟悉cocos2d的人)确实有旋转值,如果有帮助的话.

谢谢.

iphone objective-c rotation accelerometer cocos2d-iphone

13
推荐指数
1
解决办法
3086
查看次数

不同的UITableViewCell高度

我在故事板中构建了三个不同的单元格,并将所有出口连接起来,每个单元格都有一个唯一的标识符.

例如,我有一个包含图片的单元格,另一个包含标签的单元格,另一个包含其他内容,因此它们都是唯一的,每个单元格类型都需要自己的高度(动态或状态,无关紧要).

但是,我怎么能用'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)

iphone objective-c uitableview ipad

13
推荐指数
2
解决办法
1万
查看次数

导航栏iOS 5上有多个按钮?

我知道这个主题有很多,但我无法获得任何代码.我正在运行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)

objective-c ios

13
推荐指数
1
解决办法
1万
查看次数

TextField 使用 setState 失去焦点

我有一个习惯StatefulWidget,当输入一个空字段时,它会自动在下面添加一个新的空字段,以便用户可以继续添加数据。

但是,当我使用setStateinonChanged添加新字段时,键盘被关闭并且焦点丢失在当前聚焦的字段上。

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)

keyboard focus textfield flutter

12
推荐指数
2
解决办法
3023
查看次数

动画旋转UIImageView

我想左右旋转UIImageView大约10度,但是有一个平滑的动画,而不是我看到的突然转弯:

player.transform = CGAffineTransformMakeRotation(angle)
Run Code Online (Sandbox Code Playgroud)

任何帮助表示感谢,谢谢.

iphone animation rotation uiimageview

11
推荐指数
2
解决办法
2万
查看次数

以编程方式为单个UITableViewCell设置高度?

我需要以编程方式在UITableView中设置单个UITableViewCell的高度.我怎样才能做到这一点?

我需要这个单元格高150像素,所有其他单元格可以保持默认的44像素高度.

谢谢.

iphone objective-c uitableview

11
推荐指数
3
解决办法
2万
查看次数

AVAudioPlayer,没有声音

我已经将音频工具箱和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)

零声音.非常感谢任何帮助,谢谢.

iphone audio objective-c

11
推荐指数
3
解决办法
8714
查看次数

以编程方式将UINavigationBar添加到UIView?

我试图以编程方式将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 uinavigationbar uiview ios

11
推荐指数
2
解决办法
1万
查看次数