UIAlertController is not is window hierarchy - ios

Im trying to show up a pop up containing a UIPickerView and UITextField.
Following is my code that I use to create the pop up.
self.alert = [UIAlertController alertControllerWithTitle:nil message:#"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" preferredStyle:UIAlertControllerStyleAlert];
CGRect pickerFrame = CGRectMake(0, 0, 270, 200);
UIPickerView *regionsPicker = [[UIPickerView alloc] initWithFrame:pickerFrame];
regionsPicker.tag = 1;
regionsPicker.dataSource = (id <UIPickerViewDataSource>)self;
regionsPicker.delegate = (id <UIPickerViewDelegate>) self;
[regionsPicker setShowsSelectionIndicator:YES];
UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 270.0f, 44.f)];
toolView.backgroundColor = [UIColor blackColor];
CGRect buttonFrame = CGRectMake(0, 5, 100, 30);
UIButton *button = [[UIButton alloc] initWithFrame: buttonFrame];
button.imageEdgeInsets = UIEdgeInsetsMake(0, button.titleLabel.frame.size.width, 0, -button.titleLabel.frame.size.width);
UIImage *btnImage = [UIImage imageNamed:#"delete.png"];
[button setImage:btnImage forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitleColor: [UIColor blueColor] forState: UIControlStateNormal];
[toolView addSubview:button];
[button addTarget:self action:#selector(closeDialog:) forControlEvents:UIControlEventTouchUpInside];
self.textField = [[UITextView alloc] initWithFrame:CGRectMake(30, 170, 220, 200)];
_textField.editable = NO;
_textField.hidden=true;
self.textField.text = #"Enter text...";
self.textField.font = [UIFont systemFontOfSize:15];
self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
self.textField.keyboardType = UIKeyboardTypeDefault;
self.textField.returnKeyType = UIReturnKeyDone;
self.textField.textColor = [UIColor lightGrayColor];
self.textField.delegate = (id <UITextViewDelegate>) self;
self.textField.layer.borderWidth = 1.0f;
self.textField.layer.cornerRadius = 5;
self.textField.layer.borderColor = [[UIColor grayColor] CGColor];
[toolView addSubview:self.textField];
CGRect actionFrame = CGRectMake(80, 400, 100, 30);
UIButton *actionBtn = [[UIButton alloc] initWithFrame: actionFrame];
[actionBtn setTitle:#"Submit" forState:UIControlStateNormal];
[actionBtn setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];
[actionBtn setBackgroundColor:[UIColor purpleColor]];
[self.textField setUserInteractionEnabled:YES];
[toolView setUserInteractionEnabled:YES];
[self.alert.view setUserInteractionEnabled:YES];
[self.alert.view addSubview:regionsPicker];
[self.alert.view addSubview:self.textField];
[self.alert.view addSubview:toolView];
[self.alert.view addSubview:actionBtn];
id rootViewController=[UIApplication sharedApplication].delegate.window.rootViewController;
if([rootViewController isKindOfClass:[UINavigationController class]])
{
rootViewController=[((UINavigationController *)rootViewController).viewControllers objectAtIndex:0];
}
[rootViewController presentViewController:_alert animated:YES completion:nil];
It works fine.However, if Im trying to enter text in the UITextField by tapping it, the keyboard doesn't appear and hence Im not be able to type anything within the UITextField. How can I sort this out?

the reason is you added textField, button, all those inside toolview , but the toolview height is very less
change your toolView height from 44
into 500 or else (combination of textfield, button + 50).
Change below statement
UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 270.0f, 44.f)];
to
UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 270.0f, 500.f)];
Update
change this line
[self presentViewController:alert animated:YES completion:nil];
into
id rootViewController=[UIApplication sharedApplication].delegate.window.rootViewController;
if([rootViewController isKindOfClass:[UINavigationController class]])
{
rootViewController=[((UINavigationController *)rootViewController).viewControllers objectAtIndex:0];
}
[rootViewController presentViewController:alert animated:YES completion:nil];
Update New
UIViewController *rootViewController=[UIApplication sharedApplication].delegate.window.rootViewController;
if([rootViewController isKindOfClass:[UINavigationController class]])
{
rootViewController=[((UINavigationController *)rootViewController).viewControllers objectAtIndex:0];
}else
{
while (rootViewController.presentedViewController) {
rootViewController = rootViewController.presentedViewController;
}
}
[rootViewController presentViewController:alert animated:YES completion:nil];
Swift
var rootViewController: UIViewController = UIApplication.sharedApplication().delegate.window.rootViewController
if (rootViewController is UINavigationController.self) {
rootViewController = ((rootViewController as! UINavigationController)).viewControllers[0]
}
else {
while rootViewController.presentedViewController {
rootViewController = rootViewController.presentedViewController
}
}
rootViewController.presentViewController(alert, animated: true, completion: { _ in })

Try this it may help you:-
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:#" Your message " preferredStyle:UIAlertControllerStyleAlert];
UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 270, 200)];
toolView.backgroundColor = [UIColor blackColor];
CGRect buttonFrame = CGRectMake(0, 5, 100, 30);
UIButton *button = [[UIButton alloc] initWithFrame:buttonFrame];
[button setTitle:#"Image" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[toolView addSubview:button];
UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 270, 44)];
txtField.borderStyle = UITextBorderStyleRoundedRect;
txtField.backgroundColor = [UIColor grayColor];
txtField.font = [UIFont systemFontOfSize:15];
txtField.placeholder = #"enter text";
txtField.autocorrectionType = UITextAutocorrectionTypeNo;
txtField.keyboardType = UIKeyboardTypeDefault;
txtField.returnKeyType = UIReturnKeyDone;
txtField.clearButtonMode = UITextFieldViewModeWhileEditing;
txtField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
txtField.delegate = (id<UITextFieldDelegate>)self;
[toolView addSubview:txtField];
[txtField setUserInteractionEnabled:YES];
[toolView setUserInteractionEnabled:YES];
[alertController.view setUserInteractionEnabled:YES];
[alertController.view addSubview:toolView];
[self presentViewController:alertController animated:YES completion:nil];

Related

titleView jumps after segue

In my app I have a UINavigationController with a UISplitViewController as rootViewController. The masterViewController of this UISplitViewController sets a UIView with a UITextField centered inside it as titleView. This is wat it looks like in the storyboard.
- (void)viewDidLoad {
[super viewDidLoad];
self.titleView = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-((self.view.frame.size.width/2)+150))/2, 0, (self.view.frame.size.width/2)+150, 30)];
self.rightButton = [[UIButton alloc] init];
[self.rightButton setImage:newImage forState:UIControlStateNormal];
[self.rightButton addTarget:self action:#selector(barButtonRight:) forControlEvents:UIControlEventTouchUpInside];
self.rightButton.frame = CGRectMake(0, 0, 30, 30);
self.rightButton.tintColor = [UIColor whiteColor];
[self.rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:self.rightButton];
self.splitViewController.navigationItem.rightBarButtonItem = rightButton;
self.textField = [[UITextField alloc]init];
if (IDIOM == IPAD) {
self.textField.frame = CGRectMake(0, 0, self.titleView.frame.size.width, 30);
} else {
self.textField.frame = CGRectMake(65, 0, (self.view.frame.size.width-20)-110, 30);
}
self.textField.backgroundColor = [UIColor purpleColor];
if (IDIOM == IPAD) {
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 20)];
self.textField.leftView = paddingView;
self.textField.leftViewMode = UITextFieldViewModeAlways;
}
[self.titleView addSubview:self.textField];
self.splitViewController.navigationItem.titleView = self.titleView;
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
Now, when a the right button is pressed a strange thing happens.
- (IBAction)barButtonRight:(id)sender {
[self performSegueWithIdentifier:#"showDetail" sender:self];
}
The UITextField is pushed all the way to the left inside the UIView. I commented out most of my viewDidLoad code and this is still happening. Any ideas as to what's causing this?

iOS- Objective C - Show a view on ipad only but hide on iPhone

I need a solution for the problem described below..
I have a scenario where a view needs to be shown only on ipad but it needs to be hidden on iphone. The way the view is built is as follows:
The below code shows the view on ipad. I want to hide this view when loaded on iphone.
How can this be achieved?
(void)viewDidLoad
{
[super viewDidLoad];
gotQuoteList = NO;
isExpanded = NO;
heightOfUploadManager = 282;
freqQuotesArray = [[NSMutableArray alloc] init];
selectedCheckboxes = [[NSMutableDictionary alloc] init];
serviceConfig_G_Obj = [[ServiceConfig alloc] init];
cacheManager_G_Obj = [[CacheManager alloc] init];
[self.view setBackgroundColor: [[UIColor whiteColor] colorWithAlphaComponent:0.5f]];
[self observeRotationChanges];
uploadMngrView = [[UIView alloc] init];
[self setUploadManagerFrame];
[uploadMngrView setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
uploadMngrView.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
uploadMngrView.layer.borderWidth = 1.0;
[self.view addSubview:uploadMngrView];
UIView *titleLblBgView = [[UIView alloc] init];
[titleLblBgView setFrame:CGRectMake(0, 40, 512, 1)];
[titleLblBgView setBackgroundColor:[self colorWithHexString:#"C7C7C7"]];
[uploadMngrView addSubview:titleLblBgView];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 1, 512-21, 38)];
[titleLabel setText:#"Upload Document"];
[titleLabel setTextAlignment:NSTextAlignmentLeft];
[titleLabel setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
[titleLabel setTextColor:[self colorWithHexString:#"656565"]];
[titleLabel setFont:[UIFont fontWithName:#"Arial" size:21]];
[uploadMngrView addSubview:titleLabel];
UILabel *fileLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, 141, 34)];
[fileLabel setText:#"File"];
[fileLabel setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
[fileLabel setTextColor:[self colorWithHexString:#"656565"]];
[fileLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[uploadMngrView addSubview:fileLabel];
UILabel *fileNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(163, 60, 329, 34)];
[fileNameLabel setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:#"labelBG.png"]]];
[fileNameLabel setTextColor:[self colorWithHexString:#"656565"]];
[fileNameLabel setText:[NSString stringWithFormat:#" %#",[[self getFileName] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
[fileNameLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
fileNameLabel.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
fileNameLabel.layer.borderWidth = 1.0;
[uploadMngrView addSubview:fileNameLabel];
UILabel *destinationLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 114, 141, 34)];
[destinationLabel setTextColor:[self colorWithHexString:#"656565"]];
[destinationLabel setText:#"Destination"];
[destinationLabel setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
[destinationLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[uploadMngrView addSubview:destinationLabel];
UILabel *destinationNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(163, 114, 329, 34)];
destinationNameLabel.tag = 1;
UITapGestureRecognizer *worksaceRBTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didTapRadioBtnLabelWithGesture:)];
worksaceRBTapGestureRecognizer.numberOfTapsRequired = 1;
[destinationNameLabel setUserInteractionEnabled:YES];
[destinationNameLabel addGestureRecognizer:worksaceRBTapGestureRecognizer];
destinationNameLabel.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
destinationNameLabel.layer.borderWidth = 1.0;
[destinationNameLabel setText:#" My Workspace"];
[destinationNameLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"labelBG.png"]]]; [destinationNameLabel setTextColor:[self colorWithHexString:#"656565"]];
[destinationNameLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[uploadMngrView addSubview:destinationNameLabel];
myWorkspaceRadioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
myWorkspaceRadioBtn.tag = 1;
[myWorkspaceRadioBtn setImage:[UIImage imageNamed:#"radiobtn_off.png"] forState:UIControlStateNormal];
[myWorkspaceRadioBtn setImage:[UIImage imageNamed:#"radiobtn_on.png"] forState:UIControlStateSelected];
[myWorkspaceRadioBtn setFrame:CGRectMake(166, 121, 26, 22)];
myWorkspaceRadioBtn.selected=YES;
[myWorkspaceRadioBtn addTarget:self action:#selector(radioButton:) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:myWorkspaceRadioBtn];
UILabel *destinationQuoteLabel = [[UILabel alloc] initWithFrame:CGRectMake(163, 147, 329, 34)];
destinationQuoteLabel.tag = 2;
UITapGestureRecognizer *quotelistRBTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didTapRadioBtnLabelWithGesture:)];
quotelistRBTapGestureRecognizer.numberOfTapsRequired = 1;
[destinationQuoteLabel setUserInteractionEnabled:YES];
[destinationQuoteLabel addGestureRecognizer:quotelistRBTapGestureRecognizer];
destinationQuoteLabel.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
destinationQuoteLabel.layer.borderWidth = 1.0;
[destinationQuoteLabel setTextColor:[self colorWithHexString:#"656565"]];
[destinationQuoteLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[destinationQuoteLabel setText:#" Link to selected quote"];
[destinationQuoteLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"labelBG.png"]]];
[uploadMngrView addSubview:destinationQuoteLabel];
quoteListRadioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
quoteListRadioBtn.tag = 2;
[quoteListRadioBtn setImage:[UIImage imageNamed:#"radiobtn_off.png"] forState:UIControlStateNormal];
[quoteListRadioBtn setImage:[UIImage imageNamed:#"radiobtn_on.png"] forState:UIControlStateSelected];
[quoteListRadioBtn setFrame:CGRectMake(166, 152, 26, 22)];
[quoteListRadioBtn addTarget:self action:#selector(radioButton:) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:quoteListRadioBtn];
[self fillQuoteListScrollView];
lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 202, 512, 1)];
lineView.backgroundColor = [self colorWithHexString:#"C7C7C7"];
[uploadMngrView addSubview:lineView];
cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cancelButton setFrame:CGRectMake(20, 222, 231, 40)];
[cancelButton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
[cancelButton setTitleColor:[self colorWithHexString:#"656565"] forState:UIControlStateNormal];
[cancelButton setTitle:#"Cancel" forState:UIControlStateNormal];
CAGradientLayer *cancelBtnGradient = [CAGradientLayer layer];
cancelBtnGradient.frame = cancelButton.bounds;
cancelBtnGradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:255.0/255.0f green:255.0/255.0f blue:255.0/255.0f alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:238.0/255.0f green:238.0/255.0f blue:238.0/255.0f alpha:1.0f] CGColor], nil];
[cancelButton.layer insertSublayer:cancelBtnGradient atIndex:0];
cancelButton.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
cancelButton.layer.borderWidth = 1.0;
[cancelButton addTarget:self action:#selector(cancelUpload) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:cancelButton];
uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
[uploadButton setFrame:CGRectMake(261, 222, 231, 40)];
[uploadButton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
[uploadButton setTitleColor:[self colorWithHexString:#"55A0B9"] forState:UIControlStateNormal];
[uploadButton setTitle:#"Upload" forState:UIControlStateNormal];
CAGradientLayer *uploadBtnGradient = [CAGradientLayer layer];
uploadBtnGradient.frame = uploadButton.bounds;
uploadBtnGradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:255.0/255.0f green:255.0/255.0f blue:255.0/255.0f alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:238.0/255.0f green:238.0/255.0f blue:238.0/255.0f alpha:1.0f] CGColor], nil];
[uploadButton.layer insertSublayer:uploadBtnGradient atIndex:0];
uploadButton.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
uploadButton.layer.borderWidth = 1.0;
[uploadButton addTarget:self action:#selector(uploadDoc) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:uploadButton];
}
You can do this like this,
uploadMngrView = [[UIView alloc] init];
[self setUploadManagerFrame];
[uploadMngrView setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
uploadMngrView.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
uploadMngrView.layer.borderWidth = 1.0;
if ([UIDevice currentDevice].userInterfaceIdom == UIUserInterfaceIdoniPad) {
[self.view addSubview:uploadMngrView];
}
HTH, Enjoy Coding !!
As your setting up the views programatically, you something like this
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// Create the view only for ipad
self.someView = [[UIView alloc] initWithFrame:someFrame];
//Or set the view hidden just on ipad
self.someView.hidden = YES;
//Or set the view a different frame on ipad
self.someView.frame = CGRectMake(x,y,width,height);
}
else
{
//Do some non ipad layout stuff here
}

Dismiss custom alert view iOS

I'm setting up a subclass of UIView to roll my own UIAlertView style view. I've got everything set up properly with displaying the view, but I'm at a bit of a loss as to how to dismiss the view properly. Specifically, when a user taps on the button in the view, it needs to animate out of the main view. This is the code for the view itself:
+ (void)showCustomAlertWithTitle:(NSString *)titleString andMessage:(NSString *)messageString inView:(UIView *)view andButton1Title: (NSString *)button1Title andButton2Title: (NSString *)button2Title
{
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
CGRect windowFrame = window.frame;
[view setAlpha:0.5f];
UIColor *buttonColor = [UIColor colorWithRed:0/255.0f green:130/255.0f blue:216/255.0f alpha:1];
UIColor *titleColor = [UIColor colorWithRed:0/255.0f green:153/255.0f blue:102/255.0f alpha:1];
// Shade
UILabel *shadeWindow = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, windowFrame.size.width, windowFrame.size.height)];
shadeWindow.backgroundColor = [UIColor blackColor];
shadeWindow.alpha = 0.50f;
// Define size and origin of alert box
float alertBoxHeight = 225;
float alertBoxWidth = 200;
float alertBoxXorigin = windowFrame.size.width / 2 - (alertBoxWidth / 2);
float alertBoxYorigin = windowFrame.size.height / 2 - (alertBoxHeight / 2);
// Initialize background
UIView *alertBackground = [[UIView alloc] initWithFrame:CGRectMake(alertBoxXorigin, alertBoxYorigin, alertBoxWidth, alertBoxHeight)];
alertBackground.layer.cornerRadius = 5.0f;
[alertBackground.layer setMasksToBounds:YES];
alertBackground.layer.backgroundColor = [UIColor whiteColor].CGColor;
// Title Label
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, alertBoxWidth, 40)];
titleLabel.text = titleString;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = titleColor;
titleLabel.layer.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.05f].CGColor;
[titleLabel setFont:[UIFont fontWithName:#"AvenirNext-Bold" size:20.0]];
// Title Divider
UILabel *titleDivider = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, alertBoxWidth, 1.0)];
titleDivider.backgroundColor = [UIColor grayColor];
titleDivider.alpha = 0.5f;
// Alert Message Text
UITextView *alertMessage = [[UITextView alloc] initWithFrame:CGRectMake(0, 40, alertBoxWidth, alertBoxHeight - 90)];
alertMessage.text = messageString;
alertMessage.layer.backgroundColor = [UIColor whiteColor].CGColor;
[alertMessage setFont:[UIFont fontWithName:#"Avenir" size:15.0]];
alertMessage.textAlignment = NSTextAlignmentCenter;
alertMessage.textColor = [UIColor grayColor];
[alertMessage setEditable:NO];
// Button 1
UIButton *button1 = [[UIButton alloc] init];
UIButton *button2 = [[UIButton alloc] init];
[button1 addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
if (button2Title == nil)
{
button1.frame = CGRectMake(10, alertBoxHeight - 50, alertBoxWidth - 20, 40);
}
else
{
button1.frame = CGRectMake(10, alertBoxHeight - 50, (alertBoxWidth / 2) - 20, 40);
button2.frame = CGRectMake(alertBoxWidth / 2 + 10, alertBoxHeight - 50, (alertBoxWidth / 2) - 20, 40);
}
button1.layer.backgroundColor = buttonColor.CGColor;
[button1 setTitle:button1Title forState:UIControlStateNormal];
[button1.titleLabel setFont:[UIFont fontWithName:#"AvenirNext-Bold" size:15.0f]];
button1.layer.cornerRadius = 2.5f;
[button1.layer setMasksToBounds:YES];
// Button 2
button2.layer.backgroundColor = buttonColor.CGColor;
[button2 setTitle:button2Title forState:UIControlStateNormal];
[button2.titleLabel setFont:[UIFont fontWithName:#"AvenirNext-Bold" size:15.0f]];
button2.layer.cornerRadius = 2.5f;
[button2.layer setMasksToBounds:YES];
// Bounce Implementation
alertBackground.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^
{
alertBackground.transform = CGAffineTransformIdentity;
}
completion:^(BOOL finished)
{
// do something once the animation finishes, put it here
}];
[window addSubview:view];
[window addSubview:alertBackground];
[view addSubview:shadeWindow];
[view bringSubviewToFront:alertBackground];
[alertBackground addSubview:button1];
[alertBackground addSubview:titleLabel];
[alertBackground addSubview:titleDivider];
[alertBackground addSubview:alertMessage];
[alertBackground addSubview:button2];
[alertBackground bringSubviewToFront:titleDivider];
/* [[[customAlerts sharedInstance] subViewArray] addObject:alertBackground];
[[[customAlerts sharedInstance] subViewArray] addObject:view];
[[[customAlerts sharedInstance] subViewArray] addObject:window];*/
}
When button1 is tapped, for instance, I need to have it animate the view out of the superView and remove it from the stack. I'm not sure how to handle this. Does anyone have any ideas?
To permanently remove a view, I generally use the UIView instance method removeFromSuperview. followed by a line setting the relevant variable to nil:
[myAlertView removeFromSuperview];
myAlertView = nil;
In your case then, I think you need to move the view off the screen by animating the its bounds property, then use the above couple of lines to remove any references to it.
Just found the answer here:
Dismiss view controller from #selector without creating seperate method
Had to download some custom classes but it worked:
[button1 addEventHandler:^(id sender, UIEvent *event)
{
[UIView animateWithDuration:0.25f animations:^{
[alertBackground setAlpha:0.0f];
[shadeWindow setAlpha:0.0f];
[window setAlpha:0.0f];
}];
} forControlEvent:UIControlEventTouchUpInside];
Custom classes can be found here:
https://github.com/ZeR0-Wu/JTTargetActionBlock

iOS iCarousel image offset

Good afternoon. ICarusel I use in my application. I have an image that is loaded as image view. Images are placed exactly in the center. Please tell me how do I move the image up to only 50 pixels in it without moving the rest of the content?
The method for creating views like that:
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
NSString *docDir = [NSHomeDirectory() stringByAppendingPathComponent:#"Library/Caches"];
NSDictionary *myDic =[magazinesInfo objectAtIndex:index];
//Resize image
UIImage *img = [UIImage imageWithImage:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/%#_img.png",docDir,[myDic objectForKey:#"title"]]] scaledToSize:CGSizeMake(375,510)];
UIImageView *romb = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 118, 135)];
UIImageView *faceImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,768,1004)];
UIImage *dwImage = [UIImage imageNamed:#"button.png"];
UIImage *readImage = [UIImage imageNamed:#"read_button.png"];
UIImage *deleteImage = [UIImage imageNamed:#"delete_button.png"];
if(view ==nil)
{
UIButton *myDownloadButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[myDownloadButton setBackgroundColor:[UIColor blackColor]];
[myDownloadButton setHidden:YES];
romb.image = [UIImage imageNamed:#"romb.png"];
view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 1004)];
[view setBackgroundColor:[UIColor blackColor]];
view = faceImage;
faceImage.image = nil;
((UIImageView *)view).image = nil;
view.contentMode = UIViewContentModeCenter;
//Magazine number
myLabel = [[UILabel alloc] initWithFrame:CGRectMake(345, 85, 75, 29)];
myLabel.backgroundColor = [UIColor clearColor];
myLabel.textAlignment = NSTextAlignmentCenter;
[myLabel setFont:[UIFont fontWithName:#"OpenSans-Light" size:36.0f]];
myLabel.textColor = [UIColor whiteColor];
myLabel.tag = 1;
//Magazine name
nameMag = [[UILabel alloc] initWithFrame:CGRectMake(-65, 450, 100, 100)];
nameMag.backgroundColor = [UIColor yellowColor];
nameMag.textAlignment = NSTextAlignmentCenter;
[nameMag setFont:[UIFont fontWithName:#"OpenSans-Light" size:30.0f]];
nameMag.textColor = [UIColor blackColor];
nameMag.tag = 3;
//Date
dateMag = [[UILabel alloc] initWithFrame:CGRectMake(-67, 500, 500, 30)];
dateMag.backgroundColor = [UIColor greenColor];
dateMag.textAlignment = NSTextAlignmentCenter;
[dateMag setFont:[UIFont fontWithName:#"OpenSans-Light" size:20.0f]];
dateMag.textColor = [UIColor blackColor];
dateMag.tag = 4;
//Download button
downloadButton = [[UIButton alloc] initWithFrame:CGRectMake(350, 700, 128, 37)];
[downloadButton setBackgroundImage:dwImage forState:UIControlStateNormal];
[downloadButton addTarget:self action:#selector(pressDownload:) forControlEvents:UIControlEventTouchUpInside];
downloadButton.tag = 5;
//Read button
readButton = [[UIButton alloc] initWithFrame:CGRectMake(250, 750, 128, 37)];
[readButton setBackgroundImage:readImage forState:UIControlStateNormal];
[readButton addTarget:self action:#selector(readMag:) forControlEvents:UIControlEventTouchUpInside];
readButton.hidden=YES;
readButton.tag = 8;
//Delete button
deleteButton = [[UIButton alloc] initWithFrame:CGRectMake(400, 750, 128, 37)];
[deleteButton setBackgroundImage:deleteImage forState:UIControlStateNormal];
[deleteButton addTarget:self action:#selector(deleteMag:) forControlEvents:UIControlEventTouchUpInside];
deleteButton.hidden=YES;
deleteButton.tag = 9;
//Progress bar
downloadProgress = [[UIProgressView alloc] initWithFrame:CGRectMake(100, 800, 127, 8)];
downloadPrecent = [[UILabel alloc]initWithFrame:CGRectMake(300, 800, 8, 8)];
downloadPrecent.backgroundColor = [UIColor blueColor];
[downloadPrecent setFont:[UIFont fontWithName:#"OpenSans-Light" size:20.0f]];
dateMag.textColor = [UIColor blackColor];
downloadProgress.tag = 6;
downloadPrecent.tag = 7;
downloadProgress.hidden = YES;
downloadPrecent.hidden = YES;
//Add image subview
[view addSubview:romb];
//Label subview
[view addSubview:myLabel];
[view addSubview:nameMag];
[view addSubview:dateMag];
//Progressbar subview
[view addSubview:downloadProgress];
[view addSubview:downloadPrecent];
//Buttons subview
[view addSubview:downloadButton];
[view addSubview:readButton];
[view addSubview:deleteButton];
[view addSubview:myDownloadButton];
}
else
{
romb.image = (UIImage*)[romb viewWithTag:3];
((UIImageView *)faceImage).image = (UIImage*)[view viewWithTag:2];
myLabel = (UILabel *)[view viewWithTag:1];
nameMag = (UILabel *)[view viewWithTag:3];
dateMag = (UILabel *)[view viewWithTag:4];
downloadProgress = (UIProgressView *) [view viewWithTag:6];
downloadPrecent = (UILabel *)[view viewWithTag:7];
downloadButton = (UIButton *) [view viewWithTag:5];
readButton = (UIButton *) [view viewWithTag:8];
deleteButton = (UIButton*) [view viewWithTag:9];
}
NSFileManager *fileManager = [NSFileManager defaultManager];
NSLog(#"index is: %i",index);
NSLog(#"current item index %i",[self.carousel currentItemIndex]);
NSLog(#"%hhd",[fileManager fileExistsAtPath:[NSString stringWithFormat:#"%#/%#_mag.pdf",docDir,[myDic objectForKey:#"title"]]]);
if ([fileManager fileExistsAtPath:[NSString stringWithFormat:#"%#/%#_mag.pdf",docDir,[myDic objectForKey:#"title"]]] == YES && (index == [self.carousel currentItemIndex]))
{
NSLog(#"%#",[[view subviews] objectAtIndex:9]);
[[[view subviews] objectAtIndex:9] setHidden:NO];
readButton.hidden = NO;
deleteButton.hidden = NO;
downloadButton.hidden = YES;
}
else
{
[[[view subviews] objectAtIndex:9] setHidden:YES];
readButton.hidden = YES;
deleteButton.hidden = YES;
downloadButton.hidden = NO;
}
((UIImageView *)view).image = img;
myLabel.text = [myDic objectForKey:#"title"];
dateMag.text = [myDic objectForKey:#"date"];
romb.image = [UIImage imageNamed:#"romb.png"];
return view;
}
Now it looks like this (do not worry, it's still developing :))
http://files.mail.ru/B2B41BA915624173B646184D4283D9F9?t=1
Use the contentOffset property to shift the carousel contents relative to the carousel view without changing their perspective.
You can use the viewpointOffset propert instead if you want it to look like the perspective has changed (i.e as if you are looking at the carousel from below).

iPad popover presentpopoverfrombarbuttonitem

I have added a few buttons to the right side of the navigation bar with the following:
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
customView.backgroundColor = [UIColor clearColor];
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 45, 44);
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button.backgroundColor = [UIColor clearColor];
[button setImage:[UIImage imageNamed:#"toc.png"] forState:UIControlStateNormal];
button.userInteractionEnabled = YES;
[button addTarget:self action:#selector(tableOfContentsAction) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:button];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(50, 0, 45, 44);
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button.backgroundColor = [UIColor clearColor];
[button setImage:[UIImage imageNamed:#"bookmark.png"] forState:UIControlStateNormal];
button.userInteractionEnabled = YES;
[button addTarget:self action:#selector(bookmarkButtonAction) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:button];
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:customView];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[customView release];
[segmentBarItem release];
This works well. For both buttons I show a popOver as shown below
- (void) bookmarkButtonAction
{
BookmarksViewController* content = [[BookmarksViewController alloc] initWithOrientation:lastOrientation selectedPage:selectedPage];
UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:content];
CGSize size = content.view.frame.size;
aPopover.popoverContentSize = size;
aPopover.delegate = self;
self.bookmarksPopoverVC = content;
self.bookmarksPopoverVC.popUpController = aPopover;
[content release];
[aPopover presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[aPopover release];
bookmarksShowing = YES;
}
The problem is that I am using presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem and this shows the top arrow in the middle of the two buttons. How can I attach the arrow to each button?
instead of using this line:
aPopover presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem
You may better try this line:
aPopover presentPopoverFromBarButtonItem:sender
I think that would solve your problem
try this:
- (IBAction)products:(id)sender {
UIButton* btn = (UIButton *)sender;
[productsPopover presentPopoverFromRect:[btn bounds] inView:btn permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Works like a charm

Resources