小编Mee*_*shi的帖子

如何使用IBOutletCollection将多个UIImageView连接到同一个插座?

我有10个UIImageViews做同样的事情(他们有一些void方法,用计时器改变他们的图像).我的UIImageView是一个插座,我想将所有10个imageView连接到同一个插座,但界面构建器不允许我.

我发现有一个解决方案,IBOutletCollection.任何人都可以向我解释如何使用它将多个imageView连接到同一个插座?

xcode objective-c uiimageview ios iboutletcollection

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

从IPhone SDK中的视频网址创建缩略图

我正在尝试从视频网址获取缩略图.视频是具有m3u8格式的流(HLS).我已经尝试过来自MPMoviePlayerController的requestThumbnailImagesAtTimes,但是没有用.有没有人有解决这个问题的方法?如果是这样你怎么做的?

video objective-c thumbnails ios

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

更改锁屏背景音频控制文字?

我有一个iOS应用程序,使用AVAudioSession流式传输背景音频.它工作正常,但我很好奇,有没有办法改变锁屏音频控件上的文字?现在它只显示我的应用程序的名称,但我想将其更改为轨道的名称.

此外,多任务栏在控件下没有文字 - 有没有办法在那里添加曲目名称,就像iPod应用程序一样?

objective-c ios avaudiosession mpnowplayinginfocenter swift

27
推荐指数
1
解决办法
9367
查看次数

如何将视频文件保存到文档目录中

我正在使用以下代码捕获视频:

UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType =  UIImagePickerControllerSourceTypeCamera;
ipc.delegate = self;
//need to handle delegates methods 
//
ipc.allowsEditing = YES;
ipc.videoQuality = UIImagePickerControllerQualityTypeMedium;
ipc.videoMaximumDuration = 30.0f; // 30 seconds
//temporary duation of 30 seconds for testing

ipc.mediaTypes = [NSArray arrayWithObject:@"public.movie"];
// ipc.mediaTypes = [NSArray arrayWithObjects:@"public.movie", @"public.image", nil];
[self presentModalViewController:ipc animated:YES]; 
//this controller allows to record the videos
Run Code Online (Sandbox Code Playgroud)

我可以使用以下代码将录制的视频保存到相册

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{ 
    // recover video URL
    NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];

    // check if video is …
Run Code Online (Sandbox Code Playgroud)

iphone video objective-c ios

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

iOS Pinch Scale和Two Finger同时旋转

这是我的代码:

viewDidLoad中:

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinch:)];
[self.canvas addGestureRecognizer:pinch];
pinch.delegate = self;

UIRotationGestureRecognizer *twoFingersRotate = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(pinchRotate:)];
[[self canvas] addGestureRecognizer:twoFingersRotate];

twoFingersRotate.delegate = self;
Run Code Online (Sandbox Code Playgroud)

捏和旋转代码:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

-(void)pinchRotate:(UIRotationGestureRecognizer*)rotate
{
    SMImage *selectedImage = [DataCenter sharedDataCenter].selectedImage;

    switch (rotate.state) 
    {
        case UIGestureRecognizerStateBegan:
        {
            selectedImage.referenceTransform = selectedImage.transform;
            break;
        }
        case UIGestureRecognizerStateChanged:
        {
            selectedImage.transform = CGAffineTransformRotate(selectedImage.referenceTransform, ([rotate rotation] * 55) * M_PI/180);
            break;
        }

        default:
            break;
    }
}

-(void)pinch:(UIPinchGestureRecognizer*)pinch
{
    SMImage *selectedImage = [DataCenter sharedDataCenter].selectedImage;
    [self itemSelected]; …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c ipad ios

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

无法在Interface Builder中连接IBOutlet

我有一种奇怪的经历.我创建任何类型的iPhone应用程序,添加一个带有Xib文件的UIViewController.我可以使用控件编辑xib文件,如果我运行则查看它们.现在我正在尝试向控制器添加一些IBOutlets,因此我将它们添加到.h文件中,在.m文件上进行合成.然后我转到Interface Builder连接插座.我将UILabel拖到UIView,然后我尝试连接文件所有者(我的自定义UIViewController),但是当我尝试连接到UILabel时,我可以选择的所有内容都是"查看",这显然是错误的.所以我无法将IBOutlets连接到Interface Builder中的控件.

有任何想法吗?

iphone interface-builder ios

25
推荐指数
3
解决办法
4万
查看次数

在iOS中从提供的视图控制器推送视图

简而言之: 我如何从呈现的ViewController中推送PushController?

简单来说 :

我有MainViewController,我点击按钮时有一个按钮,我正在展示一个叫做的视图LoginViewController.

在这个页面上(LoginViewController),我再次button点击它,我尝试推动我的视图控制器(称为HomeViewController)它不会推动.

这是我的代码片段,

MainViewController.m

- (IBAction)LoginClicked:(id)sender {
    LoginViewController *vc = [[LoginViewController alloc] init];
    [self presentViewController:vc animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

LoginViewController.m

- (IBAction)buttonActionMethodOnLoginView:(id)sender{
     NSLog(@"viewControllers %@",APPDELEGATE.nav.viewControllers);
     //LoginViewController is not in this array
     HomeViewController *obj = [[HomeViewController alloc] init];
     [self.navigationController pushViewController:obj animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

但它对我不起作用.另外,我a stack of view controllers之前打印过pushed,但它没有LoginViewController.因此,无需添加LoginViewController到a stack of view controllers,我怎样才能pushed到HomeViewController从LoginViewController?

当我从中获取时HomeViewController …

objective-c uinavigationcontroller pushviewcontroller ios presentviewcontroller

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

调整图像大小以适合UIImageView

我对目标c很新,我只是在考虑我的方向.我想做一些非常简单的事情,但事实证明这是一个很大的挑战:

我试图将图像显示为UIImageView.我显示的图像很大,我希望它按比例缩小以适应UIImageView.我尝试设置AspectFit视图模式,但图像显示为原始大小,并被剪切UIImageView.我的代码如下:

- (void)changeImages
{
    UIImage* img11 = nil;

    img11 = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"jpeg"]];

    u11.contentMode = UIViewContentModeScaleAspectFit;
    u11.image = img11;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self changeImages];
}
Run Code Online (Sandbox Code Playgroud)

有人可以对此有所了解吗?

谢谢!

objective-c uiimageview uiimage ios

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

如何在以编程方式创建的UILabel上添加padding-left?

我知道这是一个菜鸟问题,但是...我在桌面视图上有这些标签,但文字完全被压到了左边.我想添加一些填充.我该怎么办呢?

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section  {

    UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(10,0,300,60)] autorelease];

    UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];

    headerLabel.backgroundColor = [UIColor colorWithHexString:[[_months objectAtIndex:section] objectForKey:@"color"]];
    headerLabel.font = [UIFont boldSystemFontOfSize:18];
    headerLabel.frame = CGRectMake(0,0,400,30);
    headerLabel.text =  [[_months objectAtIndex:section] objectForKey:@"name"];

    headerLabel.textColor = [UIColor whiteColor];


    [customView addSubview:headerLabel];

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

任何帮助深表感谢!谢谢!

iphone objective-c ios

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

从BLE设备读取数据

我正在尝试从蓝牙设备(BR-LE4.0-S2)读取数据.我能够连接BLE设备,但无法从中读取数据.我没有关于BLE服务及其特性的任何规范.这是我的问题- (void)peripheral:didUpdateValueForCharacteristic:error:没有被调用.我按照教程" https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/PerformingCommonCentralRoleTasks/PerformingCommonCentralRoleTasks.html#perapple_ref/doc/uid/TP40013257-CH3-SW2 ".以下是我的码.

我的要求是从BLE设备连续读取数据.任何帮助是极大的赞赏.

- (void)viewDidLoad
{
    self.myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
    self.peripheral = [[CBPeripheral alloc] init];
    self.peripheral.delegate = self;
    [super viewDidLoad];
}

- (void) centralManagerDidUpdateState:(CBCentralManager *)central {

    switch (central.state) {
        case CBCentralManagerStatePoweredOn:
        [self.myCentralManager scanForPeripheralsWithServices:nil options:nil];
            break;
        default:
            NSLog(@"Central Manager did change state");
            break;
    }

}

- (void)centralManager:(CBCentralManager *)central
 didDiscoverPeripheral:(CBPeripheral *)peripheral
     advertisementData:(NSDictionary *)advertisementData
                  RSSI:(NSNumber *)RSSI {

    NSLog(@"Discovered %@", peripheral.name);
    [self.myCentralManager stopScan];
    NSLog(@"Scanning stopped");

    if (self.peripheral != peripheral) {
        self.peripheral = peripheral;
        NSLog(@"Connecting to peripheral %@", peripheral); …
Run Code Online (Sandbox Code Playgroud)

objective-c ios core-bluetooth

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