Block size image when I enlarge the view
I have a view and within an image that works as a button. I would like to know if there is a way to lock the size of the button so that when I zoom in, the view remains small and does not enlarge with the view..
ios swift image size
add a comment |
I have a view and within an image that works as a button. I would like to know if there is a way to lock the size of the button so that when I zoom in, the view remains small and does not enlarge with the view..
ios swift image size
imageView.contentMode = .center
?
– Tamás Sengel
Nov 20 '18 at 14:10
@TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted
– user10652382
Nov 20 '18 at 14:12
That's what.center
(and also.left
,.right
etc.) does. Try it out.
– Tamás Sengel
Nov 20 '18 at 14:13
@TamásSengel no not work, I check now..
– user10652382
Nov 20 '18 at 14:17
add a comment |
I have a view and within an image that works as a button. I would like to know if there is a way to lock the size of the button so that when I zoom in, the view remains small and does not enlarge with the view..
ios swift image size
I have a view and within an image that works as a button. I would like to know if there is a way to lock the size of the button so that when I zoom in, the view remains small and does not enlarge with the view..
ios swift image size
ios swift image size
edited Nov 20 '18 at 14:49
Scriptable
13.3k43554
13.3k43554
asked Nov 20 '18 at 14:05
user10652382
imageView.contentMode = .center
?
– Tamás Sengel
Nov 20 '18 at 14:10
@TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted
– user10652382
Nov 20 '18 at 14:12
That's what.center
(and also.left
,.right
etc.) does. Try it out.
– Tamás Sengel
Nov 20 '18 at 14:13
@TamásSengel no not work, I check now..
– user10652382
Nov 20 '18 at 14:17
add a comment |
imageView.contentMode = .center
?
– Tamás Sengel
Nov 20 '18 at 14:10
@TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted
– user10652382
Nov 20 '18 at 14:12
That's what.center
(and also.left
,.right
etc.) does. Try it out.
– Tamás Sengel
Nov 20 '18 at 14:13
@TamásSengel no not work, I check now..
– user10652382
Nov 20 '18 at 14:17
imageView.contentMode = .center
?– Tamás Sengel
Nov 20 '18 at 14:10
imageView.contentMode = .center
?– Tamás Sengel
Nov 20 '18 at 14:10
@TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted
– user10652382
Nov 20 '18 at 14:12
@TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted
– user10652382
Nov 20 '18 at 14:12
That's what
.center
(and also .left
, .right
etc.) does. Try it out.– Tamás Sengel
Nov 20 '18 at 14:13
That's what
.center
(and also .left
, .right
etc.) does. Try it out.– Tamás Sengel
Nov 20 '18 at 14:13
@TamásSengel no not work, I check now..
– user10652382
Nov 20 '18 at 14:17
@TamásSengel no not work, I check now..
– user10652382
Nov 20 '18 at 14:17
add a comment |
2 Answers
2
active
oldest
votes
I thought it was hard to manager in the beginning. But finally, if you put the imageView in a UIScrollView, It's not hard to achieve.
The idea is move the buttonView outside of imageView during zooming and when zoom is over, put it back to imageView to pretend nothing happened. I know it's too verbose in programming but actually it works perfectly for your case.
var originalCenter : CGPoint! // The center of ButtonView in imageView.
//All functions are from the UIScrollViewDelegate.
func viewForZooming(in scrollView: UIScrollView) -> UIView?{
originalCenter = buttonView.center // remember the original position.
return imageView
}
func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
buttonView.frame = imageView.convert(buttonView.frame, to: scrollView)
scrollView.addSubview(buttonView)//add to superView of imageImage.
}
func scrollViewDidZoom(_ scrollView: UIScrollView){
buttonView.center = imageView.convert(originalCenter, to: scrollView) //During Zooming, update the buttonView in ScrollView.
}
func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat){
buttonView.frame = imageView.convert(buttonView.frame, from: scrollView)
imageView.addSubview(buttonView) //put it back.
}
I know it's better to use a parameter to control such operation. But I have-not found one according to public APIs. Maybe there is a better way, hope this one is your answer too.
add a comment |
Because you called transform for superView. It will make all subViews inside transform together.
You need to remake you views:
SuperView:
- Content view (the image view)
- Border view
- Button close
When you want to zoom the image, you only need to reset the superview frame.
You found a git SPUserResizableView
.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394785%2fblock-size-image-when-i-enlarge-the-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I thought it was hard to manager in the beginning. But finally, if you put the imageView in a UIScrollView, It's not hard to achieve.
The idea is move the buttonView outside of imageView during zooming and when zoom is over, put it back to imageView to pretend nothing happened. I know it's too verbose in programming but actually it works perfectly for your case.
var originalCenter : CGPoint! // The center of ButtonView in imageView.
//All functions are from the UIScrollViewDelegate.
func viewForZooming(in scrollView: UIScrollView) -> UIView?{
originalCenter = buttonView.center // remember the original position.
return imageView
}
func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
buttonView.frame = imageView.convert(buttonView.frame, to: scrollView)
scrollView.addSubview(buttonView)//add to superView of imageImage.
}
func scrollViewDidZoom(_ scrollView: UIScrollView){
buttonView.center = imageView.convert(originalCenter, to: scrollView) //During Zooming, update the buttonView in ScrollView.
}
func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat){
buttonView.frame = imageView.convert(buttonView.frame, from: scrollView)
imageView.addSubview(buttonView) //put it back.
}
I know it's better to use a parameter to control such operation. But I have-not found one according to public APIs. Maybe there is a better way, hope this one is your answer too.
add a comment |
I thought it was hard to manager in the beginning. But finally, if you put the imageView in a UIScrollView, It's not hard to achieve.
The idea is move the buttonView outside of imageView during zooming and when zoom is over, put it back to imageView to pretend nothing happened. I know it's too verbose in programming but actually it works perfectly for your case.
var originalCenter : CGPoint! // The center of ButtonView in imageView.
//All functions are from the UIScrollViewDelegate.
func viewForZooming(in scrollView: UIScrollView) -> UIView?{
originalCenter = buttonView.center // remember the original position.
return imageView
}
func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
buttonView.frame = imageView.convert(buttonView.frame, to: scrollView)
scrollView.addSubview(buttonView)//add to superView of imageImage.
}
func scrollViewDidZoom(_ scrollView: UIScrollView){
buttonView.center = imageView.convert(originalCenter, to: scrollView) //During Zooming, update the buttonView in ScrollView.
}
func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat){
buttonView.frame = imageView.convert(buttonView.frame, from: scrollView)
imageView.addSubview(buttonView) //put it back.
}
I know it's better to use a parameter to control such operation. But I have-not found one according to public APIs. Maybe there is a better way, hope this one is your answer too.
add a comment |
I thought it was hard to manager in the beginning. But finally, if you put the imageView in a UIScrollView, It's not hard to achieve.
The idea is move the buttonView outside of imageView during zooming and when zoom is over, put it back to imageView to pretend nothing happened. I know it's too verbose in programming but actually it works perfectly for your case.
var originalCenter : CGPoint! // The center of ButtonView in imageView.
//All functions are from the UIScrollViewDelegate.
func viewForZooming(in scrollView: UIScrollView) -> UIView?{
originalCenter = buttonView.center // remember the original position.
return imageView
}
func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
buttonView.frame = imageView.convert(buttonView.frame, to: scrollView)
scrollView.addSubview(buttonView)//add to superView of imageImage.
}
func scrollViewDidZoom(_ scrollView: UIScrollView){
buttonView.center = imageView.convert(originalCenter, to: scrollView) //During Zooming, update the buttonView in ScrollView.
}
func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat){
buttonView.frame = imageView.convert(buttonView.frame, from: scrollView)
imageView.addSubview(buttonView) //put it back.
}
I know it's better to use a parameter to control such operation. But I have-not found one according to public APIs. Maybe there is a better way, hope this one is your answer too.
I thought it was hard to manager in the beginning. But finally, if you put the imageView in a UIScrollView, It's not hard to achieve.
The idea is move the buttonView outside of imageView during zooming and when zoom is over, put it back to imageView to pretend nothing happened. I know it's too verbose in programming but actually it works perfectly for your case.
var originalCenter : CGPoint! // The center of ButtonView in imageView.
//All functions are from the UIScrollViewDelegate.
func viewForZooming(in scrollView: UIScrollView) -> UIView?{
originalCenter = buttonView.center // remember the original position.
return imageView
}
func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
buttonView.frame = imageView.convert(buttonView.frame, to: scrollView)
scrollView.addSubview(buttonView)//add to superView of imageImage.
}
func scrollViewDidZoom(_ scrollView: UIScrollView){
buttonView.center = imageView.convert(originalCenter, to: scrollView) //During Zooming, update the buttonView in ScrollView.
}
func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat){
buttonView.frame = imageView.convert(buttonView.frame, from: scrollView)
imageView.addSubview(buttonView) //put it back.
}
I know it's better to use a parameter to control such operation. But I have-not found one according to public APIs. Maybe there is a better way, hope this one is your answer too.
answered Nov 21 '18 at 1:09
E.ComsE.Coms
2,5652414
2,5652414
add a comment |
add a comment |
Because you called transform for superView. It will make all subViews inside transform together.
You need to remake you views:
SuperView:
- Content view (the image view)
- Border view
- Button close
When you want to zoom the image, you only need to reset the superview frame.
You found a git SPUserResizableView
.
add a comment |
Because you called transform for superView. It will make all subViews inside transform together.
You need to remake you views:
SuperView:
- Content view (the image view)
- Border view
- Button close
When you want to zoom the image, you only need to reset the superview frame.
You found a git SPUserResizableView
.
add a comment |
Because you called transform for superView. It will make all subViews inside transform together.
You need to remake you views:
SuperView:
- Content view (the image view)
- Border view
- Button close
When you want to zoom the image, you only need to reset the superview frame.
You found a git SPUserResizableView
.
Because you called transform for superView. It will make all subViews inside transform together.
You need to remake you views:
SuperView:
- Content view (the image view)
- Border view
- Button close
When you want to zoom the image, you only need to reset the superview frame.
You found a git SPUserResizableView
.
edited Nov 22 '18 at 15:09
rmaddy
243k27321383
243k27321383
answered Nov 21 '18 at 4:56
TienLeTienLe
2421527
2421527
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394785%2fblock-size-image-when-i-enlarge-the-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
imageView.contentMode = .center
?– Tamás Sengel
Nov 20 '18 at 14:10
@TamásSengel I do not have to center the image, but make sure that it does not enlarge when I enlarge the view in which it is inserted
– user10652382
Nov 20 '18 at 14:12
That's what
.center
(and also.left
,.right
etc.) does. Try it out.– Tamás Sengel
Nov 20 '18 at 14:13
@TamásSengel no not work, I check now..
– user10652382
Nov 20 '18 at 14:17