В моем приложении у меня есть галерея горизонтального изображения, в которой при нажатии на изображение отображается UIView
, отображая увеличенные изображения. UIView
содержит, scrollView
, imageviews
(динамически созданный) и программный код UIButton
(кнопка закрытия). Однако, когда я нажимаю кнопку закрытия, UIView
не уволен. В моем viewDidLoad Я установил gestureRecognizer
.Закрыть UIView, когда UIButton прослушивается
[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapAction:)]];
Вот мой singleTapAction метод:
- (void)singleTapAction:(UIGestureRecognizer *)singleTap_
{
MTGalleryPopUp* galleryImage = [[[NSBundle mainBundle] loadNibNamed:@"MTGalleryPopUp" owner:self options:nil] lastObject];
if(galleryImage.hidden)
{
NSLog(@"HIDDEN");
[galleryImage dismissWithAnimation:YES];
}
else
{
NSLog(@"NOT HIDDEN");
[self showGalleryDialog];
}
}
Вот мой showGalleryDialog метод:
- (void)showGalleryDialog
{
MTGalleryPopUp * galleryView = [[[NSBundle mainBundle] loadNibNamed:@"MTGalleryPopUp" owner:self options:nil] lastObject];
[galleryView setReferenceVC:self];
[galleryView initWithTitle:@"Image Gallery"];
[galleryView setAlpha:0.0f];
[self.view addSubview:galleryView];
[UIView beginAnimations:nil context:nil];
[galleryView setAlpha:1.0];
[UIView commitAnimations];
}
Вот как я создаю UIView
:
- (id)initWithTitle:(NSString *)aTitle
{
CGRect rect = [[UIScreen mainScreen] bounds]; // portrait bounds
if (self = [super initWithFrame:rect])
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
[self setBackgroundColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.8f]];
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, TITLE_HEIGHT, screenRect.size.width, 350)];
[self.scrollView setUserInteractionEnabled:YES];
CloseButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[CloseButton addTarget:self
action:@selector(dismissWithAnimation:)
forControlEvents:UIControlEventTouchUpInside];
[CloseButton setTitle:@"X" forState:UIControlStateNormal];
[CloseButton.layer setBorderWidth:2];
[CloseButton.layer setBorderColor:[UIColor whiteColor].CGColor];
CloseButton.layer.cornerRadius=10;
CloseButton.layer.masksToBounds = YES;
[CloseButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
CloseButton.titleLabel.font=[UIFont systemFontOfSize:16];
CloseButton.frame=CGRectMake(self.frame.size.width-80, 8, 20, 20);
[self addSubview:CloseButton];
strURL = [NSString stringWithFormat:@"%@%@?temp_url_sig=%@&temp_url_expires=%lld", URLstorage, CONTAINER_PATH, HMACStr, [@(floor([oneMinLater timeIntervalSince1970])) longLongValue]];
[mutableURLstorage addObject:strURL];
[imagesArray addObject:[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]]]];
}
CGSize pageSize = CGSizeMake(ITEM_WIDTH, self.scrollView.frame.size.height);
_pgCtr = [[UIPageControl alloc] initWithFrame:CGRectMake(0, screenRect.size.height-30, 320, 36)];
_pgCtr.backgroundColor=[UIColor grayColor];
int numberofPage=ceil((float)[imagesArray count]/2.5);
_pgCtr.numberOfPages= numberofPage;
self.scrollView.contentSize = CGSizeMake(450*numberofPage, pageSize.height);
int imgCurrentX = 10;
for (UIImageView* image in imagesArray)
{
@autoreleasepool
{
imageview = [[UIImageView alloc] initWithFrame:CGRectMake(imgCurrentX, 45, 200, self.scrollView.frame.size.height - 10)];
imageview.image = (UIImage*)image;
[imageview setUserInteractionEnabled:YES];
[self.scrollView addSubview:imageview];
imgCurrentX = imgCurrentX + 220;
}
}
[self addSubview:self.scrollView];
}
return self;
}
Когда я нахожусь в отладке, что происходит, он возвращается к методу singleTap_ и снова воссоздает UIView
(теперь два UIViews
перекрываются). Что я здесь делаю неправильно?
Любая помощь будет очень оценена. Благодарю.
вам нужно показать и скрыть один вид на кране, я прав? –
@PravinTate yep..Я пробовал все. -_- –
вам нужен код для показа и скрытия uiview при нажатии кнопки, вправо –