小编oni*_*ivi的帖子

以编程方式更改UIView大小

我有一个UIView,我想在用户触摸按钮时改变大小.

CGRect newFrame = self.myview.frame;

newFrame.size.width = 200;
newFrame.size.height = 200;
[self setFrame:newFrame];

CGRect newFrame = self.searchField.frame;

newFrame.size.width = 200;
newFrame.size.height = 200;
self.searchField.frame=newFrame;
Run Code Online (Sandbox Code Playgroud)

它们都不起作用,不改变任何东西.我想为UIView设置固定的宽度和高度.

iphone uiview ios

43
推荐指数
4
解决办法
9万
查看次数

指定UICollectionView的行号和列号

我想显示一个UICollectionView,每行包含2行和100个单元格.

// 1
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {

    return 100;
}
// 2
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
    return 2;
}
// 3
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MyCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

        cell.lbl.text = @"Data";

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

我得到这个:

在此输入图像描述

如何为UICollectionView指定行号?我想创建一个2x100表.

ios uicollectionview uicollectionviewcell

20
推荐指数
4
解决办法
5万
查看次数

不会触发commitEditingStyle

我有一个UITableView,我试图在编辑模式处于活动状态时删除一行,但不会触发commitEditingStyle.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.text=[NSString stringWithFormat:@"Row Number %d",indexPath.row];

    return cell;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"trying to delete a row..");
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}

-(void)Edit:(id)sender //Active editing mode
{
    [self.table setEditing:YES animated:YES];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Done:)]; …
Run Code Online (Sandbox Code Playgroud)

uitableview ios

9
推荐指数
1
解决办法
3952
查看次数

如何在iPhone模拟器文件夹下找到我的应用程序文件?

如何轻松访问我正在处理的应用程序的文件夹.

在此输入图像描述

iPhone Simulator目录下有太多应用程序文件夹,如何访问任何特定文件夹?

ios ios-simulator

8
推荐指数
2
解决办法
5450
查看次数

获取*.mov视频IOS的缩略图

我想获得一个用iPhone/iPAD拍摄的视频缩略图(*.mov).我试图使用AVFoundation库并得到此错误:

couldn't generate thumbnail, error:Error Domain=AVFoundationErrorDomain Code=-11822 "Cannot Open" UserInfo=0x15d90a30 {NSLocalizedDescription=Cannot Open, NSLocalizedFailureReason=This media format is not supported.}
Run Code Online (Sandbox Code Playgroud)

码:

NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir=[paths objectAtIndex:0];
NSString *videoPath=[documentDir stringByAppendingPathComponent:[NSString stringWithFormat:@"videos/%@.mov",videoName]];


    AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:videoPath options:nil];
    AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    generator.appliesPreferredTrackTransform=TRUE;

    CMTime thumbTime = CMTimeMakeWithSeconds(0,30);

    AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
        if (result != AVAssetImageGeneratorSucceeded) {
            NSLog(@"couldn't generate thumbnail, error:%@", error);
        }
        self.img.image=[UIImage imageWithCGImage:im];
    };

    CGSize maxSize = CGSizeMake(320, 180);
    generator.maximumSize = …
Run Code Online (Sandbox Code Playgroud)

iphone video avfoundation ios video-thumbnails

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