Tag: Objective C

点击时如何放大UIImageView

我对编程很新,所以我在尝试这样做时遇到了一些问题。 我有一个在UIImageView中显示图像的应用程序,我希望当用户点击它时图像放大。 我认为最简单的方法是在UIImageView上隐藏一个半透明按钮,并在用户点击它时触发一个动作。 这就是我能得到的,我不知道我的行动方法应该是什么样子。 这是我到目前为止: – (IBAction)enlargeImage1:(id)sender { CGRect myImageRect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 80.0f); UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect]; [myImage setImage:[UIImage imageNamed:@”gradient-253×80.png”]]; [self.view addSubview:myImage]; } 我的UIImageView被命名为imageView,我将上面的方法附加到imageView上的UIButton。 当我点击图像时,它根本不会放大。 非常感谢任何帮助或建议,谢谢!

如果CGImageCreate的数据提供者使用应用程序创建的数组,那么对CGImageCreate的正确调用是什么样的呢?

我正在尝试在内存中创建一个位图作为模式函数的一部分,drawLayer:inContext:方法(此方法是CALayer委托协议的一部分)将调用。 模式函数看起来类似于: static const size_t kComponentsPerPixel = 4; static const size_t kBitsPerComponent = sizeof(unsigned char) * 8; NSInteger layerHeight = 160; NSInteger layerWidth = 160; CGContextSaveGState(context); CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); size_t bufferLength = layerWidth * layerHeight * kComponentsPerPixel; unsigned char *buffer = malloc(bufferLength); // The real function does something more interesting with the buffer, but […]

mapViewDidFinishLoadingMap:调用得太早了

我的问题很简单:我正在等待获取MKMapView的截图,我想只在加载地图后才这样做。 不幸的是, 在实际加载地图之前 ,几乎总是调用此委托方法。 如果我很幸运的话,我只会得到一个网格,或者几个加载的瓷砖。 有没有办法做我需要做的事情? 或者我错过了MKMapViewDelegate协议中的内容? 谢谢!

正确设置BOOL属性的方法

我有一个BOOL属性,我想在我的类初始化程序中设置。 @property (assign, nonatomic) BOOL isEditMode; – (id)init { . . . [self setValue:NO forKey:isEditMode]; return self; } 编译器给我一个“不兼容的整数到指针转换”警告。 我在这做错了什么?

无法在iOS上以后台模式重新启动中断的音频输入队列

我正在使用AudioQueue编写iOS应用程序进行录制。 我创建了一个配置为获得线性PCM的输入队列,声明了这个队列,一切都按预期工作。 为了管理中断,我实现了AVAudioSession的委托方法来捕获中断的开始和结束。 endInterruption方法如下所示: – (void)endInterruptionWithFlags:(NSUInteger)flags; { if (flags == AVAudioSessionInterruptionFlags_ShouldResume && audioQueue != 0) { NSLog(@”Current audio session – category: ‘%@’ mode: ‘%@'”, [[AVAudioSession sharedInstance] category], [[AVAudioSession sharedInstance] mode]); NSError *error = nil; OSStatus errorStatus; if ((errorStatus = AudioSessionSetActive(true)) != noErr) { error = [self errorForAudioSessionServiceWithOSStatus:errorStatus]; NSLog(@”Could not reactivate the audio session: %@”, [error […]

我是否需要为NSObject调用或等

通常,当我从UI类inheritance时,我将调用感兴趣的超类初始化程序。 但是,我不确定NSObject的实现细节,似乎在成员变量方面没有太多进展,所以我想知道:如果我的子类扩展NSObject我是否需要调用[super init] ?

UIWebView加载本地video数据

我正在尝试在UIWebView中加载video。 video存储在本地文件系统中。 这是我用于加载video的代码段。 { NSString* filePAth = [[NSBundle mainBundle] pathForResource:@”sample_iPod” ofType:@”m4v”]; NSLog(@”%@”,filePAth); NSData* data = [NSData dataWithContentsOfFile:filePAth]; [_webView loadData:data MIMEType:@”video/x-m4v” textEncodingName:@”UTF-8″ baseURL:nil]; } 这是我在控制台中遇到的错误: Webview加载出错:错误Domain = WebKitErrorDomain Code = 204“Plug-in handling load”UserInfo = 0x1f8b3c70 {NSErrorFailingURLStringKey = applewebdata:// 3F0047AD-E6CF-4EAD-A4C3-DA6E1C0BD603,WebKitErrorMIMETypeKey = video / x-m4v,NSErrorFailingURLKey = applewebdata :// 3F0047AD-E6CF-4EAD-A4C3-DA6E1C0BD603,NSLocalizedDescription =插件处理负载} 但是,相同的代码适用于加载所有其他文件类型,例如:PNG,DOC等。 请帮忙…!!!

为现有联系人添加电话号码

我正在尝试使用AddressBook框架向现有联系人添加电话号码,在选择具有选择器的人员后调用此方法: – (BOOL) peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { if(_phoneNumber != nil) { ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutableCopy (ABRecordCopyValue(person, kABPersonPhoneProperty)); ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFTypeRef)_phoneNumber, kABPersonPhoneOtherFAXLabel, NULL); ABRecordSetValue(person, kABPersonPhoneProperty, multiPhone,nil); CFRelease(multiPhone); } return FALSE; } 但在此之后,该号码不会添加到此人的记录中。 我究竟做错了什么?

更快的MPMediaItems的NSMutableArray? 代码审查

我有几周的时间进入iOS编程,还有很多需要学习的地方。 我有一种包含MPMediaItems的NSMutableArray工作,但是它有大约10秒的速度,有1200种物品,我正在寻找一种更快的方法。 我的最终目标是拥有一系列MPMediaItemCollection项目,每个项目代表一个专辑。 我不能从MPMediaQuery(据我所知)得到这个,因为我需要从播放列表中获取歌曲。 所以我正在对从特定播放列表(“过去4个月”)中获得的歌曲进行排序,然后构建我自己的集合数组。 正如我所说,下面的方法有效但速度很慢。 即使我只按MPMediaItemPropertyAlbumTitle排序,它仍然需要大约4秒钟(iPhone 4S)。 编辑:我应该提到我尝试排序描述符,但我无法获得工作的关键。 例如 NSSortDescriptor *titleDescriptor = [[NSSortDescriptor alloc] initWithKey:@”MPMediaItemPropertyAlbumTitle” ascending:YES]; 这会返回错误 [ valueForUndefinedKey:]: this class is not key value coding-compliant for the key MPMediaItemPropertyAlbumTitle. 代码 MPMediaQuery *query = [MPMediaQuery playlistsQuery]; NSArray *playlists = [query collections]; NSMutableArray *songArray = [[NSMutableArray alloc] init]; for (MPMediaItemCollection *playlist in playlists) { NSString […]

UIButton图像resize/缩放以适应

我有一个非常有线的问题,我不知道如何解决它。 我正在设置UIButtons框架的动画,当我为它设置动画时,我希望按钮中的图像缩放到与按钮相同的大小。 它可以在我的iPhone模拟器上无需任何操作。 但是当我在iPad模拟器上运行它时,它不会改变图像大小。 我在几个地方添加了[[gissaImg1 imageView] setContentMode:UIViewContentModeScaleToFill]代码,但它没有帮助。 有谁知道什么是错的,以及如何解决这个问题? //Code to set the image UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@”%@_small”, [[itemsForRound objectAtIndex:[[guessItems objectAtIndex:0] intValue]] valueForKey:@”Name”]]]; [self.gissaImg1 setImage:image forState:UIControlStateNormal]; [self.gissaImg1 setImage:image forState:UIControlStateHighlighted]; //Code to animate button CGRect animateToSpot = (isIphone) ? CGRectMake(0, 0, 480, 320) : CGRectMake(0, 0, 1024, 768); [self performSelector:@selector(PlayCorrectSound:) withObject:nil afterDelay:1]; [[gissaImg1 imageView] setContentMode:UIViewContentModeScaleToFill]; […]