我一直在尝试为图像视图实现视差效果.视差效果的代码很简单,它只在我添加时才UIImage有效UIImageView.我有一个模式图像,需要在两侧平铺自己.
所以我不得不使用patternWithImage方法UIColor.当我进行视差工作时,但是self.view当我倾斜设备时,我可以看到边缘的背景颜色.
这是一个代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.backgroundImageView.contentMode = UIViewContentModeCenter;
self.backgroundImageView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"connect"]];
[self addParallaxEffectToView:self.backgroundImageView];
}
- (void)addParallaxEffectToView:(UIView *)view
{
// Set vertical effect
UIInterpolatingMotionEffect *verticalMotionEffect =
[[UIInterpolatingMotionEffect alloc]
initWithKeyPath:@"center.y"
type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
verticalMotionEffect.minimumRelativeValue = @(-50);
verticalMotionEffect.maximumRelativeValue = @(50);
// Set horizontal effect
UIInterpolatingMotionEffect *horizontalMotionEffect =
[[UIInterpolatingMotionEffect alloc]
initWithKeyPath:@"center.x"
type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
horizontalMotionEffect.minimumRelativeValue = @(-50);
horizontalMotionEffect.maximumRelativeValue = @(50);
// Create group to …Run Code Online (Sandbox Code Playgroud) 我有一个地图视图,有10个商店位置,数据来自webservice.我只想推送到我的详细视图,以显示点击的商店的地址,电话和其他信息.
detailview当用户点击或在内部触摸到mapkit上的注释时,我需要将数据传递给我.在我mapview和我想知道的第一个中有10个注释,我如何理解或如何获得单击注释的注释ID?
这是我返回引脚的方法
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]]) return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.pinColor=MKPinAnnotationColorPurple;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
return pinView;
}
/* and my action method for clicked or tapped annotation: */
- (IBAction)showDetails:(id)sender{
NSLog(@"Annotation Click");
[[mtMap selectedAnnotations]objectAtIndex:0];
magazaDetayViewController *detail = [[magazaDetayViewController
alloc]initWithNibName:@"magazaDetayViewController" bundle:nil];
detail.sehir=@"";
detail.magazaAdi=@"";
detail.adres=@"";
detail.telefon=@"";
detail.fax=@"";
[self.navigationController …Run Code Online (Sandbox Code Playgroud) 我使用以下代码QuartzCore为我创建了一个阴影UITextView.
myTextView.layer.masksToBounds = NO;
myTextView.layer.shadowColor = [UIColor blackColor].CGColor;
myTextView.layer.shadowOpacity = 0.7f;
myTextView.layer.shadowOffset = CGSizeMake(2.0f, 2.0f);
myTextView.layer.shadowRadius = 8.0f;
myTextView.layer.shouldRasterize = YES;
Run Code Online (Sandbox Code Playgroud)
它创建了一个shadow,looks good too.这里是上面代码的输出.

但是当我尝试添加文本时myTextView,我的textView文本超出了界限,它看起来myTextView不像下面那样.

只有当我添加阴影时才会发生这种情况.里面的文字textView并没有显示出怪异如果我不加阴影.我做错了什么?我怎么能克服这个?为什么会这样?
更新:
@borrrden说我发现它正在发生,因为设置maskToBounds = NO;如果我们设置YES然后我们不能得到阴影.原因这是一个答案
如何改变的大小宽度UIImagePickerController上iPad?我可以改变高度,所以它是700但不能改变宽度,它仍然是320.我的代码.
UIImagePickerController* imagePicker=[[UIImagePickerController alloc]init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate=self;
CGRect myRect = CGRectMake(imagePicker.view.frame.origin.x, imagePicker.view.frame.origin.y, 720, 700);
imagePicker.view.frame = myRect;
self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
myRect = CGRectMake(100, 880, 900, 900);
CGRect re2 = CGRectMake(0,0,800,800);
[self.popover setPopoverContentSize:re2.size];
[self.popover presentPopoverFromRect:[self.view bounds] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.popover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.popover setPopoverContentSize:re2.size];
Run Code Online (Sandbox Code Playgroud) objective-c uiimagepickercontroller ipad uipopovercontroller ios
我想制作多个目录,我不知道如何.这是我的代码到现在为止.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"tops",@"bottoms",@"right" ];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil]; //Create folder
}
Run Code Online (Sandbox Code Playgroud)
我希望有4个目录名为tops bottomoms left and left但是如果我以上述方式执行它就不起作用..有没有办法使用这个代码创建多个目录?还是我的代码错了?谢谢!
我有一个iPhone应用程序,缩放到用户位置的最近城市,我希望用户能够双击userLocation注释,并让地图放大到一个块左右.
如何获取userLocation注释以识别它被点击?
我有一个NSMutableArray类型的对象NSMutableDictionary,
在NSMutableDictionary包含2个键
- 航空公司(String)
-Rating(整数)
我有一个NSMutableArray所有的对象,我需要的是总结所有航空公司重复对象的评级,一个例子:
Airline Rating
A 2
B 3
B 4
C 5
Run Code Online (Sandbox Code Playgroud)
最终结果数组将是A = 2,C = 5和B的总和等于7.
我的代码到目前为止:
for (int i = 0; i < arrayMealRating.count; ++i) {
NSMutableDictionary *item = [arrayMealRating objectAtIndex:i];
NSLog(@"item=%@",item);
for (int j = i+1; j < arrayMealRating.count; ++j)
{
if ([[item valueForKey:@"Airline"] isEqualToString:[arrayMealRating objectAtIndex:j]]){
NSMutableDictionary *item = [arrayMealRating objectAtIndex:j];
NSMutableDictionary *item1 = [arrayMealRating objectAtIndex:i];
NSInteger auxCount = [[item valueForKey:@"setMealRating"] integerValue] + [[item1 valueForKey:@"setMealRating"] …Run Code Online (Sandbox Code Playgroud) 是.你是对的.当然这是一个重复的问题.在提出我的问题之前,请继续阅读以下内容.
我想舍入一个浮点值,即
56.6748939 to 56.7
56.45678 to 56.5
56.234589 to 56.2
Run Code Online (Sandbox Code Playgroud)
实际上它可以是任意数量的小数精度.但我想把它四舍五入到最接近的值.(如果大于或等于5,则向上舍入,如果不是,则向下舍入).
我可以用下面的代码来做到这一点.
float value = 56.68899
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc]init];
[numberFormatter setMaximumFractionDigits:1];
[numberFormatter setRoundingMode:NSNumberFormatterRoundUp];
NSString *roundedString = [numberFormatter stringFromNumber:[NSNumber numberWithFloat:value]];
NSNumber *roundedNumber = [NSNumber numberFromString:roundedString];
float roundedValue = [roundedNumber floatValue];
Run Code Online (Sandbox Code Playgroud)
以上代码看起来像一个漫长的过程.我有几个数字可以完善.所以这个过程很难将浮点值转换为NSNumber和NSString以及NSNumber和float.
有没有其他简单的方法来实现我的要求?
我仍然对上面的代码有疑问.它说roundUp.所以当谈到roundDown它时,它会起作用吗?
ios ×8
iphone ×3
objective-c ×3
mkmapview ×2
annotations ×1
directory ×1
ipad ×1
mkannotation ×1
quartz-core ×1
rounding ×1
shadow ×1
swift ×1
uicolor ×1
uiimageview ×1
uitextview ×1
userlocation ×1